ImportError: cannot import name 'flags' from 'MDAnalysis.core'

216 views
Skip to first unread message

Pulok Kanti Deb

unread,
Oct 13, 2020, 6:02:19 PM10/13/20
to MDnalysis discussion
Dear All,

Would you please help me to resolve this error? I can't solved it. Thank you
Comments below: 

Traceback (most recent call last):
  File "/home/pulokdeb/projects/def-xxxxxx/pulokdeb/beluga_python/Closest_atom_Oxy_group.py", line 18, in <module>
    import MDAnalysis as mda
  File "/home/pulokdeb/ENV/lib/python3.8/site-packages/MDAnalysis/__init__.py", line 211, in <module>
    from .core.universe import Universe, as_Universe, Merge
  File "/home/pulokdeb/ENV/lib/python3.8/site-packages/MDAnalysis/core/universe.py", line 101, in <module>
    from .topology import Topology
  File "/home/pulokdeb/ENV/lib/python3.8/site-packages/MDAnalysis/core/topology.py", line 64, in <module>
    from .topologyattrs import Atomindices, Resindices, Segindices
  File "/home/pulokdeb/ENV/lib/python3.8/site-packages/MDAnalysis/core/topologyattrs.py", line 51, in <module>
    from . import flags
ImportError: cannot import name 'flags' from 'MDAnalysis.core' (/home/pulokdeb/ENV/lib/python3.8/site-packages/MDAnalysis/core/__init__.py)

Pulok

Oliver Beckstein

unread,
Oct 13, 2020, 7:17:51 PM10/13/20
to mdnalysis-...@googlegroups.com
Hello Pulok,

Welcome to the MDAnalysis mailing list!

The flags were removed in MDAnalysis 1.0 so it’s odd to see such an error.

1. How did you install MDAnalysis?
2. Is this an official release of MDAnalysis or was the source code changed?
3. What is the output of 

python -c 'import MDAnalysis as mda; print(mda.__version__)'

   (i.e., which version of MDAnalysis is installed?)

Ultimately, you will likely just have to re-install MDAnalysis with something like ‘pip install --upgrade MDAnalysis’ or ‘conda update MDAnalysis’ but  it would be good to understand where your error comes from, just in case the installation is unusual.

Oliver
--
Oliver Beckstein (he/him)






irfan....@googlemail.com

unread,
Oct 13, 2020, 7:22:09 PM10/13/20
to MDnalysis discussion
Hi,

What version of MDAnalysis do you have installed?

The `flags` functionality was removed in MDAnalysis 1.0, however considering the error trace you posted, it seems like you could be using an older version?

Best regards,

Irfan 

Pulok Kanti Deb

unread,
Oct 14, 2020, 11:36:43 AM10/14/20
to mdnalysis-...@googlegroups.com
Hi Oliver, and Irfan

1. How did you install MDAnalysis? Answer: using command  "pip install  MDAnalysis[analysis] MDAnalysis Tests" in my compute cluster. Then I applied "pip install --upgrade MDAnalysis".
 I found this instruction:

(ENV) [pulokdeb@beluga1 pulokdeb]$ pip install --upgrade MDAnalysis
Ignoring pip: markers 'python_version < "3"' don't match your environment
Looking in links: /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/nix/avx512, /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/nix/avx2, /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/nix/generic, /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic
Requirement already up-to-date: MDAnalysis in /home/pulokdeb/ENV/lib/python3.8/site-packages (1.0.0)
Requirement already satisfied, skipping upgrade: mmtf-python>=1.0.0 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from MDAnalysis) (1.1.2)
Requirement already satisfied, skipping upgrade: scipy>=1.0.0 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from MDAnalysis) (1.5.2)
Requirement already satisfied, skipping upgrade: GridDataFormats>=0.4.0 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from MDAnalysis) (0.5.0)
Requirement already satisfied, skipping upgrade: joblib>=0.12 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from MDAnalysis) (0.17.0)
Requirement already satisfied, skipping upgrade: tqdm>=4.43.0 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from MDAnalysis) (4.50.2)
Requirement already satisfied, skipping upgrade: mock in /home/pulokdeb/ENV/lib/python3.8/site-packages (from MDAnalysis) (4.0.2)
Requirement already satisfied, skipping upgrade: gsd>=1.4.0 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from MDAnalysis) (1.9.3)
Requirement already satisfied, skipping upgrade: networkx>=1.0 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from MDAnalysis) (2.5)
Requirement already satisfied, skipping upgrade: matplotlib>=1.5.1 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from MDAnalysis) (3.2.1)
Requirement already satisfied, skipping upgrade: biopython>=1.71 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from MDAnalysis) (1.77)
Requirement already satisfied, skipping upgrade: numpy>=1.13.3 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from MDAnalysis) (1.19.1)
Requirement already satisfied, skipping upgrade: six>=1.4.0 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from MDAnalysis) (1.15.0)
Requirement already satisfied, skipping upgrade: msgpack>=0.5.6 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from mmtf-python>=1.0.0->MDAnalysis) (0.6.2)
Requirement already satisfied, skipping upgrade: decorator>=4.3.0 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from networkx>=1.0->MDAnalysis) (4.4.2)
Requirement already satisfied, skipping upgrade: cycler>=0.10 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from matplotlib>=1.5.1->MDAnalysis) (0.10.0)
Requirement already satisfied, skipping upgrade: python-dateutil>=2.1 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from matplotlib>=1.5.1->MDAnalysis) (2.8.1)
Requirement already satisfied, skipping upgrade: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from matplotlib>=1.5.1->MDAnalysis) (2.4.7)
Requirement already satisfied, skipping upgrade: kiwisolver>=1.0.1 in /home/pulokdeb/ENV/lib/python3.8/site-packages (from matplotlib>=1.5.1->MDAnalysis) (1.2.0)



2. Is this an official release of MDAnalysis or was the source code changed? Answer: noting change yet.
3. What is the output of version? Answer: I am not sure, how I will get it.

How can I re-install it (MDAnalysis)? Any command?

Thank you for your supports.

Pulok

--
You received this message because you are subscribed to the Google Groups "MDnalysis discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mdnalysis-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mdnalysis-discussion/55c50bba-167f-4fc6-9dc1-bfa0c500c86fn%40googlegroups.com.

Oliver Beckstein

unread,
Oct 14, 2020, 12:46:24 PM10/14/20
to mdnalysis-...@googlegroups.com
Hi Pulok,

Normally, to find the version

python -c "import MDAnalysis as mda; print(mda.__version__)”

If that fails, paste the error message and then try

grep '^__version__’  /home/pulokdeb/ENV/lib/python3.8/site-packages/MDAnalysis/version.py

and show the output.

Which version of python are you running?

python --version


I assume you’re in a virtualenv “ENV”, right? Did you recently create it or was it created for you? Just in case, we have some notes https://www.mdanalysis.org/2017/04/07/environments/#python-virtual-environments. You could always try making a completely fresh environment.

(ENV) [pulokdeb@beluga1 pulokdeb]$ pip install --upgrade MDAnalysis
Ignoring pip: markers 'python_version < "3"' don't match your environment

What does the line "Ignoring pip: markers 'python_version < "3"' don't match your environment” mean? This could be a sign that there’s a configuration error? 
Are you installing Python packages from the package index https://pypi.org/ ? specifically, for me ‘pip install -v mdanalysis’ indicates that it gets files from https://pypi.org/simple/mdanalysis/

If this is NOT the case (i.e. you’re not installing a PyPi package) then you should contact the staff that manage your cluster. There might be an issue with how their custom package installation works.


Although pip installation is fully supported and works for almost everyone, when issues arise we also recommend you look into installing with conda (see the linked page above and https://www.mdanalysis.org/pages/installation_quick_start/ ) as this tends to avoid many problems.


If you want to continue with pip, I would first try uninstalling MDAnalysis

pip uninstall -v MDAnalysis

Run the above command repeatedly until it says that there’s nothing left to uninstall.

Then 

pip install -v --ugrade MDAnalysis[analysis] 2>&1 | tee mda_pip.log

Keep the output file mda_pip.log, just in case we want to look at the details.

Once that works, do the same uninstall/install with MDAnalysisTests.


If things still fail, attach the file /home/pulokdeb/ENV/lib/python3.8/site-packages/MDAnalysis/core/__init__.py to your email.

Oliver 

Oliver Beckstein (he/him)






Pulok Kanti Deb

unread,
Oct 14, 2020, 6:15:07 PM10/14/20
to mdnalysis-...@googlegroups.com
Hi Oliver
I did the installation (ENV and MDAnalysis) process again and tried to run most of the command. I also updated all the installation. I attached 2 files here for your reference. This time I installed Python (vs. 3.7).
Thanks
Pulok

--
You received this message because you are subscribed to the Google Groups "MDnalysis discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mdnalysis-discus...@googlegroups.com.
__init__.py
mda_pip.log

Oliver Beckstein

unread,
Oct 14, 2020, 6:54:37 PM10/14/20
to mdnalysis-...@googlegroups.com
Hi Pulok,

Did it work this time? 

The __init__.py file looks like the correct one.

From your log file it does not look as if MDA had to be reinstalled:

Installed version (1.0.0) is most up-to-date […]
Requirement already up-to-date: MDAnalysis[analysis] in /home/pulokdeb/ENV/lib/python3.7/site-packages (1.0.0)

But if it works now, I wouldn’t worry. Can you do

python -c "import MDAnalysis as mda; print(mda.__version__)”

Oliver


Pulok Kanti Deb

unread,
Oct 14, 2020, 8:28:59 PM10/14/20
to mdnalysis-...@googlegroups.com
Hi Oliver

Simulation just started for running. I will let you know the result.

Pulok

Pulok Kanti Deb

unread,
Oct 15, 2020, 11:28:04 AM10/15/20
to mdnalysis-...@googlegroups.com
Hello:
After installing all stuff newly, I run my simulation and got this error - 

Traceback (most recent call last):
  File "/home/pulokdeb/projects/def-sohrabz/pulokdeb/beluga_python/Closest_atom_Oxy_group.py", line 242, in <module>
    eigen_value = iio.eigen_vals()
  File "/home/pulokdeb/ENV/lib/python3.7/site-packages/MDAnalysis/core/topologyattrs.py", line 1345, in eigen_vals
    pbc = kwargs.pop('pbc', flags['use_pbc'])
NameError: name 'flags' is not defined

I attached " topologyattrs.py " file for your reference. 

Any suggestions to solve Name Error?

Thank you
Pulok
topologyattrs.py

Oliver Beckstein

unread,
Oct 15, 2020, 1:26:47 PM10/15/20
to mdnalysis-...@googlegroups.com
Hello Pulok,

Looking at the file I find 

    def eigen_vals(group, **kwargs):
        """ Changed by Ali Ghamartale
        """
        atomgroup = group.atoms
        pbc = kwargs.pop('pbc', flags['use_pbc'])
        masses = atomgroup.masses

        com = atomgroup.center_of_mass(pbc=pbc)
        if pbc:
            recenteredpos = atomgroup.pack_into_box(inplace=False) - com
        else:
            recenteredpos = atomgroup.positions - com
        tensor = np.zeros((3, 3))

        for x in range(recenteredpos.shape[0]):
            tensor += masses[x] * np.outer(recenteredpos[x, :],
                                           recenteredpos[x, :])
        tensor /= atomgroup.total_mass()
        eig_vals = np.linalg.eigvalsh(tensor)


        return eig_vals

This looks like a modified version of MDAnalysis because this code does not exist in the 1.0.0 release (compare to code near https://github.com/MDAnalysis/mdanalysis/blob/4365f3b07c1bf2ebcf16424b26162102954c5b90/package/MDAnalysis/core/topologyattrs.py#L1338) . Please contact the person who modified the code to fix it. It might be as simple as setting a default for the ‘pbc’ keyword that does not use flags.  However, adding topologyattributes can be a bit tricky and you (or anyone else) is welcome to ask on the mailing list for advice on how to best do it.

Oliver

Pulok Kanti Deb

unread,
Oct 15, 2020, 3:09:44 PM10/15/20
to mdnalysis-...@googlegroups.com
Hi Oliver

If I removed this section [you mentioned in previous email], I found this error:

Traceback (most recent call last):
  File "/home/pulokdeb/projects/def-sohrabz/pulokdeb/beluga_python/Closest_atom_Oxy_group.py", line 242, in <module>
    eigen_value = iio.eigen_vals()
  File "/home/pulokdeb/ENV/lib/python3.7/site-packages/MDAnalysis/core/groups.py", line 2289, in __getattr__
    return super(AtomGroup, self).__getattr__(attr)
  File "/home/pulokdeb/ENV/lib/python3.7/site-packages/MDAnalysis/core/groups.py", line 564, in __getattr__
    return super(GroupBase, self).__getattr__(attr)
  File "/home/pulokdeb/ENV/lib/python3.7/site-packages/MDAnalysis/core/groups.py", line 389, in __getattr__
    raise AttributeError(err)
AttributeError: AtomGroup has no attribute eigen_vals. 

Any suggestions? 

I asked the previous author about "flags", but he could not remember how this was solved for their case.

I need to solve this errors, otherwise, I can't proceed for next stages.

Thank you
Pulok



topologyattrs.py
groups.py

Oliver Beckstein

unread,
Oct 15, 2020, 4:13:35 PM10/15/20
to mdnalysis-...@googlegroups.com
Hi Pulok,

My only advice is to purge the modified version and make sure that you get an original version of MDAnalysis. Normally the staff for the cluster should be able to help with these issues. But maybe the instructions below will help. Note that if you want us to help more with these non-standard installation issues then you’ll need to provide details of the commands that you are running and ALL the output. Don’t cut anything, you might be removing details that are actually important. 

So for all what follows: have a way to collect ALL output (eg shell redirects or using the unix ‘script’ command). 

1) Uninstall your version of MDAnalysis. 

pip uninstall mdanalysis 

Do this repeatedly until it says there is nothing to uninstall. 

Show ALL output starting from the first ‘pip uninstall’ so that we can better diagnose what is happening. 

2) Then download the tar file from https://pypi.org/project/MDAnalysis/#files 

3) You will install from this file to make sure that this is a clean version of MDAnalysis. 

pip install --upgrade MDAnalysis-1.0.0.tar.gz 

Again, capture ALL output and show it  

4) Test

python -c “import MDAnalysis as mda; print(mda.__version__)”

Then try your own code. 

Oliver


Am 15.10.2020 um 12:09 schrieb Pulok Kanti Deb <pulo...@gmail.com>:



Oliver Beckstein

unread,
Oct 19, 2020, 3:53:02 PM10/19/20
to MDnalysis discussion
Hi Pulok,

Did you try the steps 1-4 in my previous email? If so, what was the output?

It generally does not help to just repost the question (here or on StackOverflow). When we ask questions then we need you to address these questions because they can provide information that we need. If you don't know how to address the questions then ask about that specifically.

Also, if you interacted with your cluster staff, tell us what you asked them and what they told you. We want to see what you've done. Don't let us guess.

Have a look at https://www.chiark.greenend.org.uk/~sgtatham/bugs.html — following these guidelines will make it a lot more likely that we can help you.

We want to help, but I have maybe 5 minutes time available to write such an email. If I can't see from your response within 5 minutes what to do then I can't answer because I have other stuff to do. It is in your interest to make it as easy as possible for us to help you. It seems clear that your problem is quite unique so it's unlikely that someone else already has a solution that they can just post. So you need to debug the problem and we can help you and to do so please address our questions when we ask them.

Oliver

Pulok Kanti Deb

unread,
Oct 20, 2020, 10:18:44 AM10/20/20
to mdnalysis-...@googlegroups.com
Hi Oliver,

My apology, I can't express my issues clearly. I kept a few screenshots and attached here. I did your steps (1-3) in my cluster (Beluga), same output. But, can't run step 4 

{python -c “import MDAnalysis as mda; print(mda.__version__)”}

I am using Mobaxterm shell for all works.

Also, our cluster staff said: (I did it on Cedar cluster)

Hello Pulok,

We have MDAnalysis wheel in our wheelhouse. You can install it in a virtual environment on graham/cedar using the following commands:

module load python/3.7.4 scipy-stack
virtualenv ~/e374

source ~/e374/bin/activate
pip install --no-index MDAnalysis 


Ignoring pip: markers 'python_version < "3"' don't match your environment
is not an error or warning. It is just an information message saying that there were packages which were not necessary to install because they were not matched by your local environment. You can safely ignore this message and start using MDAnalysis 

Please let me know if need more info that I can share for clarification.

Screenshot 2020-10-15 21.36.20.png
Screenshot 2020-10-15 21.35.58.png
Screenshot 2020-10-15 21.35.46.png
Screenshot 2020-10-15 21.38.12.png
Screenshot 2020-10-17 14.38.42.png
Screenshot 2020-10-17 14.41.51.png
Screenshot 2020-10-17 14.46.11.png
Screenshot 2020-10-17 14.43.26.png

Pulok Kanti Deb

unread,
Oct 20, 2020, 10:19:21 AM10/20/20
to mdnalysis-...@googlegroups.com
Here is mda-pip log file.
mda_pip.log

Pulok Kanti Deb

unread,
Oct 20, 2020, 3:58:09 PM10/20/20
to mdnalysis-...@googlegroups.com
Hi,

I just tried to show some output here (based on the link: https://www.mdanalysis.org/MDAnalysisTutorial/howto.html)

Please tell me if need further information.

Pulok
Screenshot 2020-10-20 17.15.07.png
Screenshot 2020-10-20 17.24.37.png
Screenshot 2020-10-20 17.17.09.png

Oliver Beckstein

unread,
Oct 20, 2020, 4:10:11 PM10/20/20
to mdnalysis-discussion
Hi Pulok,

The fact that you can import MDAnalysis in your python interpreter and get the version (namely 1.0.0)  looks already good. (I still have no idea what your original problem might have been…)

The tests package is called MDAnalysisTests (no space!!) so try

pip install MDAnalysisTests

This should install the tests. Then from inside Python try

import MDAnalysis as mda
        from MDAnalysisTests.datafiles import PSF, DCD
 
        print(mda.__version__)
u = mda.Universe(PSF, DCD)
        print(u)

By the way, the current installation docs are https://userguide.mdanalysis.org/1.0.0/installation.html#pip (the “MDAnalysisTutorial is pretty old and we recommend you use the User Guide).

Once you have installed the tests, try running them (can take up to half an hour but see https://userguide.mdanalysis.org/1.0.0/installation.html#testing). If you have more cores you can use parallel testing with test, as described at the link in the User Guide.

(Note: when I said you should run  “python -c “import MDAnalysis as mda; print(mda.__version__)”” I meant that you would run it from the command line: it runs the commands in the -c argument inside the interpreter. It does NOT mean to type everything into the Python interpreter.)

Oliver

To view this discussion on the web visit https://groups.google.com/d/msgid/mdnalysis-discussion/CAA2488JVsPN%2B5uhdy3X92eF_3t5Lr0Rfm_x8sXeLykMEEr%3D1Jw%40mail.gmail.com.
<Screenshot 2020-10-20 17.15.07.png><Screenshot 2020-10-20 17.24.37.png><Screenshot 2020-10-20 17.17.09.png>

Pulok Kanti Deb

unread,
Oct 20, 2020, 10:15:55 PM10/20/20
to mdnalysis-...@googlegroups.com
Hi Oliver, 

I solved this issue by changing a few lines in [def_eig_vals]. Here I attached the file for future reference.

Thanks a bunch for your extreme support and guidance.

Thank you
Pulok

problem-fix.txt

Pulok Kanti Deb

unread,
Oct 20, 2020, 10:19:59 PM10/20/20
to mdnalysis-...@googlegroups.com
I forget to mention that, I modified these lines in topologyattrs.py file under MDAnalysis/core.
Thank you

Oliver Beckstein

unread,
Oct 20, 2020, 10:59:18 PM10/20/20
to mdnalysis-discussion
Hi Pulok,

I am glad that you got it working with your fix. I just don’t know how this file even made it into your installation. If you installed from your local wheelhouse then that seems to indicate that someone modified the packaged version of MDAnalysis. Please keep this in mind if you encounter any problems in the future. (And consider installing a separate conda-based environment with a guaranteed pristine released version of MDAnalysis to compare to.)

Oliver

Oliver Stueker

unread,
Oct 22, 2020, 5:33:48 AM10/22/20
to mdnalysis-...@googlegroups.com
Hello Pulok and Oliver,

If you installed from your local wheelhouse then that seems to indicate that someone modified the packaged version of MDAnalysis.

I have added MDAnalysis to the Compute Canada wheelhouse and I can assure you that the code has not been modified in any way.

If Pulok's script is using a modified version of MDAnalysis, then maybe there is a secondary installation somewhere.

@Pulok: did you at any point install MDAnalysis with   pip install --user mdanalysis  ?  
If yes, there might be another installation of MDAnalysis under ~/.local/lib/python3.7/site-packages/ and the files in there would take precedence over those installed into your virtual environment.
In that case I would recommend you remove the whole ~/.local/lib/python3.7  tree and make sure you have everything you need installed in the virtualenv.

You can even have two virtual-envs: one with the unmodified MDAnalysis release and another one with the modified version from this Pull-Request https://github.com/MDAnalysis/mdanalysis/pull/2822

Happy Computing,
Oliver

Reply all
Reply to author
Forward
0 new messages