victorlei / smop

Small Matlab to Python compiler
MIT License
1.08k stars 409 forks source link

relative import path #123

Open hidetokoizumi opened 6 years ago

hidetokoizumi commented 6 years ago

Dear the author of SMOP,

I'd love to use this amazing package, followed the steps of instructions, and got the following error using Python 2.7:

Traceback (most recent call last): File "main.py", line 15, in from . import options ValueError: Attempted relative import in non-package

Looks like there are some relative path references? in the main.py, and I am wondering if you meant to delete these lines and just simply import from the smop directory.

Kindest,

victorlei commented 6 years ago

Are you working with virtualenv? Did you install smop using pip? What version it reports?

On Wed, May 30, 2018 at 12:43 AM, tarakobeam notifications@github.com wrote:

Dear the author of SMOP,

I'd love to use this amazing package, followed the steps of instructions, and got the following error using Python 2.7:

Traceback (most recent call last): File "main.py", line 15, in from . import options ValueError: Attempted relative import in non-package

Looks like there are some relative path references? in the main.py, and I am wondering if you meant to delete these lines and just simply import from the smop directory.

Kindest,

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/victorlei/smop/issues/123, or mute the thread https://github.com/notifications/unsubscribe-auth/AEhsG_mVOzJYR1qbY15Ph796ARUc_Vnbks5t3cDygaJpZM4USRR7 .

-- Calligraphy of geese / Against the sky / The moon seals it / (Buson/Hass)

hidetokoizumi commented 6 years ago

yes, but I also have python on my system in addition to anaconda-4.0.0 and anaconda3-4.0.0, and I am actually using Python2.7 on my system. I downloaded the entire zip from this GitHub page and manually installed them as instructed in the readme.

After deleting those from., it went through some steps and I am now manually getting rid of some lines that cause some errors (like !say "...").

victorlei commented 6 years ago

SMOP is supposed to work "as is", without any help from the user side. My immediate suspicion is that you are running the wrong version of SMOP. When you say SMOP --version it should respond with as version number of 0.40 at least.

hidetokoizumi commented 6 years ago

Oh, so the one here (https://github.com/victorlei/smop) is not the latest version?? I basically downloaded it with zip from the github page.

victorlei commented 6 years ago

Yes it is. But I am trying to figure out why you get an error message. Step one -- I want to be sure that you and me are running the same program. So, when you type

smop --version

at the command prompt, what output you get ?

On Wed, May 30, 2018 at 10:19 PM, tarakobeam notifications@github.com wrote:

Oh, so the one here (https://github.com/victorlei/smop) is not the latest version?? I basically downloaded it with zip from the github page.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/victorlei/smop/issues/123#issuecomment-393284833, or mute the thread https://github.com/notifications/unsubscribe-auth/AEhsG-4Zc987nSpOoQvUp939XU_QgogQks5t3vCogaJpZM4USRR7 .

-- Calligraphy of geese / Against the sky / The moon seals it / (Buson/Hass)

hidetokoizumi commented 6 years ago

nothing. I tried many alternatives, but I could not figure it out, so gave up on it with Ubuntu 16.04. Now, I am trying to install it on my Mac, OS High-Sierra, and running into some issues. I will comment on issue #124

qqrank commented 6 years ago

Excuse me for cutting in, I got the same issue,

Traceback (most recent call last): File "main.py", line 15 in from . import options ImportError: cannot import name 'options'

I tried on Python 3.6.4 |Anaconda or python 2.7 on macOS 10.13 but got the same message.

I installed this by "git clone https://github.com/victorlei/smop.git"

smop --version made the message below (regardless of installing through Python3.6.4|Anaconda or python 2.7)

Traceback (most recent call last): File "/anaconda3/bin/smop", line 11, in load_entry_point('smop==0.0.0', 'console_scripts', 'smop')() File "/anaconda3/lib/python3.6/site-packages/pkg_resources/init.py", line 572, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/anaconda3/lib/python3.6/site-packages/pkg_resources/init.py", line 2755, in load_entry_point return ep.load() File "/anaconda3/lib/python3.6/site-packages/pkg_resources/init.py", line 2408, in load return self.resolve() File "/anaconda3/lib/python3.6/site-packages/pkg_resources/init.py", line 2414, in resolve module = import(self.module_name, fromlist=['name'], level=0) File "/anaconda3/lib/python3.6/site-packages/smop-0.0.0-py3.6.egg/smop/init.py", line 4, in ModuleNotFoundError: No module named 'version'

Thankyou.

onaclov2000 commented 6 years ago

In python 2.7 I was getting the same relative import issues as originally posted near the top, I tried switching from a virtualenv of 2.7 to a conda env of 3.6 and it's saying

  File "main.py", line 15, in <module>
    from . import options
ImportError: cannot import name 'options'

I am running directly from the git folder I cloned, I didn't attempt to install

I created a fresh environment in conda with python 3 and pip installed smog

ModuleNotFoundError: No module named 'version'

Created new env with python 2.7 tried easy_install more or less it appears to have installed and worked, however the conversion failed to work.

Hope this helps someone

EvgeniyGunko commented 6 years ago

Hi, for me i just solved it when fix import paths ( example "from . import options" -> "import options" ). And then i run without installation.

Gabriel-p commented 6 years ago

The issue comes from the main.py file living inside the module's directory and being executed as a script (see here)

To fix this, move the main.py file one dir above (ie: where setup-py file is) and change its imports like so:

from . import options

to

from smop import options
victorlei commented 6 years ago

Guys please get an updated version of smop. The version on pypi was several years old and I was not aware of that. Now fixed.

On Thu, Jun 21, 2018 at 5:03 PM, Gabriel Perren notifications@github.com wrote:

The issue comes from the main.py file living inside the module's directory and being executed as a script (see here https://stackoverflow.com/questions/16981921/relative-imports-in-python-3 )

To fix this, move the main.py file one dir above (ie: where setup-py file is) and change its imports like so:

from . import options

to

from smop import options

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/victorlei/smop/issues/123#issuecomment-399114717, or mute the thread https://github.com/notifications/unsubscribe-auth/AEhsG7dgk-PphcA4vY8Nzh6TgGHVXXEQks5t-6eygaJpZM4USRR7 .

-- Calligraphy of geese / Against the sky / The moon seals it / (Buson/Hass)

Gabriel-p commented 6 years ago

I has the issue cloning the latest version in the repo, so I don't think that's the problem.

hbake001 commented 6 years ago

I know that this package is designed for python 2..but as a reminder if you are willing to use python 3 you need to fix some typos

victorlei commented 6 years ago

Please point me to the typos. All major formats accepted :)

On Sun, Jun 24, 2018 at 11:55 PM, hbake001 notifications@github.com wrote:

I know that this package is designed for python 2..but as a reminder if you are willing to use python 3 you need to fix some typos

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/victorlei/smop/issues/123#issuecomment-399786952, or mute the thread https://github.com/notifications/unsubscribe-auth/AEhsG8dwbVMBnPwRdhWcJDZZeCq6SDxxks5t__yngaJpZM4USRR7 .

-- Calligraphy of geese / Against the sky / The moon seals it / (Buson/Hass)

victorlei commented 6 years ago

There is nothing in the package that is specific to py2. In fact it does work locally with py3. Version 0.41 beta is supposed to work with py3. What are the typos?

On Sun, Jun 24, 2018 at 11:55 PM, hbake001 notifications@github.com wrote:

I know that this package is designed for python 2..but as a reminder if you are willing to use python 3 you need to fix some typos

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/victorlei/smop/issues/123#issuecomment-399786952, or mute the thread https://github.com/notifications/unsubscribe-auth/AEhsG8dwbVMBnPwRdhWcJDZZeCq6SDxxks5t__yngaJpZM4USRR7 .

-- Calligraphy of geese / Against the sky / The moon seals it / (Buson/Hass)

hbake001 commented 6 years ago

I meant it's needed to change the importing statements from

import . something to

import something Now, I ended up with the following error:


ERROR: No token list is defined
Traceback (most recent call last):
  File "main.py", line 16, in <module>
    import parse
  File "C:\Users\engadmin\Downloads\smop\smop\parse.py", line 838, in <module>
    parser = yacc.yacc(start="top")
  File "c:\users\engadmin\anaconda3\lib\site-packages\ply\yacc.py", line 3276, i
n yacc
    raise YaccError('Unable to build parser')
ply.yacc.YaccError: Unable to build parser
sandeepganji commented 6 years ago

Was anyone able to resolve the error?

File "main.py", line 15, in <module>
    from . import options
ImportError: cannot import name 'options'
RobBW commented 6 years ago

See my reply to avvaruvenkatsu on #111. It might be relevant.

Regards Rob Wilkinson

On 5/09/2018, at 07:54, Sandeep Ganji notifications@github.com wrote:

Was anyone able to resolve the error?

File "main.py", line 15, in from . import options ImportError: cannot import name 'options'

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

zwep commented 5 years ago

@sandeepganji Using the solution by @Gabriel-p worked for me.

However, I then encounter @hbake001 's problem... and this has probably something to do with me using python 3.

This is what I found on that issue thus far https://tutorials.technology/solved_errors/Python-3_6-ply-yacc-YaccError-Unable-to-build-parser.html

Which says that the package gitsome is not supported in 3.6

When I try to use pip install.. I get this error message

Collecting gitsome Downloading https://files.pythonhosted.org/packages/12/fc/495ba6a062035c26420ff3239fff7daf6e790974688cc5e728a1ebb70dfd/gitsome-0.7.2.tar.gz (314kB) Complete output from command python setup.py egg_info: gitsome currently requires Python 3.4 or 3.5

zwep commented 5 years ago

Okay.. small update.. I just tried python 3.4 and python 2.7 but with both I am getting the issue:

"ply.yacc.YaccError: Unable to build parser"

So I have no idea where to go from there..

EDIT: btw.. I am on Windows.. since I just want to convert some Matlab scripts, I was unaware what PLY actually is. So it seems that it is based on some unix libraries? Maybe that could be the source of the problem

EDIT2: Windows shouldnt matter.. since it is all written in Python of course, as is said in the README.md... Anyhow, after a simple pip instal, instead of doing python setup.py install --user, everything worked just fine.

Codeguyross commented 5 years ago

Hi, for me i just solved it when fix import paths ( example "from . import options" -> "import options" ). And then i run without installation.

This suggestion by @EvgeniyGunko worked to get the code running for me. I did a find and replace in files on "from . " to "from smop " after moving the main as suggested. I then went into the following files and added a '.' in between smop and whatever file it was referencing: options.py. parse.py. node.py, resolve.py, backend.py.

An example of this change is "from smop.version import version".

I installed smop using pip within a conda environment within python 2.7. It throws errors when running. I ran smop using the following commad "smop solver.m" from within the smop/smop folder. That led me to try the git cloned repo and I had to make the changes above to get the relative import error to go away. However, I still do not see an output from running the code. I think it is suppose to produce a "a.py" file but it produces nothing. What is suppose to happen after running smop and where can i see the result

update

I changed to python 3.6 and then installed smop using pip with the following commands and was able to get output. Im still curious why running the smop from the cloned repo wasnt working and why it still has relative import issues when being cloned:

pip install --upgrade pip
sudo pip install smop

Then run smop with: smop solver.m --output=aFile2.py

I could see an output file at this point

xinnyuann commented 2 years ago

Hi, for me i just solved it when fix import paths ( example "from . import options" -> "import options" ). And then i run without installation.

This suggestion by @EvgeniyGunko worked to get the code running for me. I did a find and replace in files on "from . " to "from smop " after moving the main as suggested. I then went into the following files and added a '.' in between smop and whatever file it was referencing: options.py. parse.py. node.py, resolve.py, backend.py.

An example of this change is "from smop.version import version".

I installed smop using pip within a conda environment within python 2.7. It throws errors when running. I ran smop using the following commad "smop solver.m" from within the smop/smop folder. That led me to try the git cloned repo and I had to make the changes above to get the relative import error to go away. However, I still do not see an output from running the code. I think it is suppose to produce a "a.py" file but it produces nothing. What is suppose to happen after running smop and where can i see the result

update# I changed to python 3.6 and then installed smop using pip with the following commands and was able to get output. Im still curious why running the smop from the cloned repo wasnt working and why it still has relative import issues when being cloned:

pip install --upgrade pip
sudo pip install smop

Then run smop with: smop solver.m --output=aFile2.py

I could see an output file at this point

Thank you so much everyone who actively noted down your problems. @Codeguyross 's solution works the best for me! I did the exact 3 commends he put above. So basically to summarize:

  1. Instead of Python 2.7, use Python3.6.
  2. Run the following 2 commends to install SMOP: pip install --upgrade pip sudo pip install smop
  3. Once it's installed, when running smop solver.m --output=aFile2.py, you get error as AttributeError: 'DiGraph' object has no attribute 'node' Errors: 1, after referring to this issue (https://github.com/victorlei/smop/issues/165), I re-installed networkx using pip install networkx==1.11 (if you have Permission error, use this commend pip install networkx==1.11 --user.
  4. Voila! Then smop works like a charm!