jewettaij / moltemplate

A general cross-platform tool for preparing simulations of molecules and complex molecular assemblies
http://www.moltemplate.org
MIT License
249 stars 98 forks source link

ImportError: cannot import name OrderedDict #56

Closed Hydrogenperoxide closed 3 years ago

Hydrogenperoxide commented 3 years ago

Hi,

I am using an Bash environment to run moltemplate on my windows 10 machine. After getting it to recognise moltemplate (v 2.19.12) as an command and making sure it recognises my python installation (v 3.9), I end up with an error message: ValueError: Attempted relative import in non-package, it enters the exception after which Bash presents me with: ImportError: cannot import name OrderedDict.

This happens both on v2.19.12 and v2.19.11 of moltemplate. The ValueError was solved by removing the "." in the moltemplate script. I struggle to find a solution for the import error.

If I write "lttree_check.py" in bash, I get the exact same error message.

I understand that this isn't a bug as per say, but I was hoping I could receive some help in getting it to work.

Thanks for your time! H2O2

jewettaij commented 3 years ago

Hi H2O2

Thanks for reporting this issue. You are using a more modern python distribution than I am.

I am using an Bash environment to run moltemplate on my windows 10 machine.

I'm curious: Are you using WSL/ubuntu or cygwin (or something else)?

After getting it to recognise moltemplate (v 2.19.12) as an command and making sure it recognises my python installation (v 3.9),

Incidentally, this seems similar to like the kind of error you can get when you are using python 2 instead of python3. (I'm curious: Is this a fresh, modern linux installation? Or is this an old linux OS that originally had python2, and you upgraded to python3? In that case it's possible that moltemplate.sh is invoking the wrong version of python on your computer. This can happen if there are multiple versions of python installed.)

I end up with an error message: ValueError: Attempted relative import in non-package, it enters the exception after which Bash presents me with: ImportError: cannot import name OrderedDict.

This happens both on v2.19.12 and v2.19.11 of moltemplate.

You don't have to try installing older versions of moltemplate. But I am curious: Have you been using moltemplate for a long time and only noticed this problem with recent versions? Or is this the first time you've tried moltemplate?

The ValueError was solved by removing the "." in the moltemplate script.

I could not follow this part of your message. What line of the moltemplate.sh script did you change?

It also helps me to know how you installed moltemplate. Did you 1) Use pip?, or did you 2) Augment your PATH (edit ~/.bashrc)?

I've found that debugging moltemplate issues, it often helps to install moltemplate by using method 2 and avoid pip. That way you can make changes to the moltemplate.sh script and see what happens. So if you installed moltemplate using pip earlier, I suggest uninstalling it, and using method 2. This might also fix the problem in the short run. (See below.)

I struggle to find a solution for the import error.

I've attached new versions of ttree.py, nbody_by_type_lib.py, and nbody_by_type.py to this message. moltemplate_source_updates_2021-7-16.zip Please unpack the archive and copy these files into the directory where they currently are located (typically ~/moltemplate/moltemplate/) and then reinstall moltemplate (preferably using method 2), and let me know if it fixes the issue.

If this does fix the issue (and if I haven't worn out your patience yet), then try installing moltemplate using method 1, and see if the problem comes back. (In that case it would tell us that this is a nasty pip/packaging related issue and not an error in the code. Packaging bugs are no fun to debug, so I hope it's not that.)

If I write "lttree_check.py" in bash, I get the exact same error message. I understand that this isn't a bug as per say, but I was hoping I could receive some help in getting it to work.

Thanks for your time! H2O2

Thanks for reporting.

Hydrogenperoxide commented 3 years ago

Hi jewattaij,

Thanks for your quick response!

Are you using WSL/ubuntu or cygwin (or something else)?

Git Bash.

Or is this the first time you've tried moltemplate?

This is indeed my first time trying moltemplate.

I'm curious: Is this a fresh, modern linux installation? Or is this an old linux OS that originally had python2, and you upgraded to python3?

I freshly installed everything to my windows 10 machine and am trying to use git bash to run the system.

It also helps me to know how you installed moltemplate. Did you

  1. Use pip?, or did you
  2. Augment your PATH (edit ~/.bashrc)?

I downloaded all the files from the github and changed the path in ~/.bashrc. After that I downloaded a Python installer from the web and installed version 3.9.

When I get back to the university, coming monday, I will try replacing the files. I will also make sure only one version of Python is installed and running on the PC.

Thanks again, H2O2

Hydrogenperoxide commented 3 years ago

I closed the issue. What I did was the following: I installed a linux VM and reinstalled everything. Leaving the windows environment solved my issues. The python version within the VM is 3.8.5 and the newest version of moltemplate is working!

Thanks so much for your patience and time!

jewettaij commented 3 years ago

That's good news. I'd love to make it easier to use moltemplate in windows, but there are several different ways to install bash and python in windows. What you did (install a linux VM, or WSL+linux) is probably the best way to set things up. So that's what I'll advocate to other windows users. Thanks for getting back to me to let me know how you fixed it. -Andrew