ImportError: cannot import name 'G' - (python3.5)
selvincephus opened this issue · 11 comments
I am trying out mecode for the first time and using python3.5 for this. I have followed the install instructions corresponding to source install in the readme file. After the install I tried the following line in the command line on Ubuntu 16.04, I get the following error. I read an earlier issue where a python 3.4 compatibility was talked about, but has there been any update in this direction since? Or is mecode not compatible with python3 generally?
~$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from mecode import G
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'G'
Did you name your python file mecode.py
?
I am assuming, when you refer to my python file, you mean a python script I've written using mecode APIs? The above example is only command line script in a linux terminal. I have not written it in a separate file. Python 2 scripts work like a charm. For example, this is using python2
$ python2
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from mecode import G
>>>
It successfully imports G from mecode.
And this is using python3,
$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from mecode import G
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'G'
>>>
Hmm, thats odd. I would guess there is some sort of install error. The tests are passing on python 3.4 and python 3.5:
https://travis-ci.org/jminardi/mecode
I am curious what is available under mecode when you import it. Can you let me know the output of the following?
import mecode
print(dir(mecode))
This is what it gives.
~$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mecode
>>> print(dir(mecode))
['__doc__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
>>>
Interesting that the python2 gives the following output.
$ python2
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mecode
>>> print(dir(mecode))
['G', 'GMatrix', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'decode2To3', 'is_str', 'main', 'matrix', 'printer']
>>>
Yeah the second one is what is expected. Were there any error messages when you installed in python 3?
It works now! I think I previously did not install mecode using python3 and pip3 in the following install steps,
$ pip install -r requirements.txt
$ python setup.py install
Thanks a ton!
Also, if I had some questions while using mecode, do I create a new issue or contact you some other way?
Great! If you have questions feel free to open another issue.
I only have Python 3 (I have 3.7.2) and I get the same readout as selvincephus does when using import mecode and print.
I installed mecode into my Downloads and extracted all, then places in the Lib folder of my python directory. I must be missing something in terms of the install
jminardi I am pretty new to this. where do I install?