Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relative import path #123

Open
hidetokoizumi opened this issue May 29, 2018 · 22 comments
Open

relative import path #123

hidetokoizumi opened this issue May 29, 2018 · 22 comments

Comments

@hidetokoizumi
Copy link

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
Copy link
Owner

victorlei commented May 29, 2018 via email

@hidetokoizumi
Copy link
Author

hidetokoizumi commented May 30, 2018

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

victorlei commented May 30, 2018 via email

@hidetokoizumi
Copy link
Author

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
Copy link

qqrank commented Jun 17, 2018

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
Copy link

onaclov2000 commented Jun 17, 2018

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
Copy link

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
Copy link

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
Copy link
Owner

victorlei commented Jun 22, 2018 via email

@Gabriel-p
Copy link

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

@hbake001
Copy link

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
Copy link
Owner

victorlei commented Jun 24, 2018 via email

@victorlei
Copy link
Owner

victorlei commented Jun 24, 2018 via email

@hbake001
Copy link

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
Copy link

Was anyone able to resolve the error?

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

@RobBW
Copy link

RobBW commented Sep 5, 2018 via email

@zwep
Copy link

zwep commented Feb 14, 2019

@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
Copy link

zwep commented Feb 14, 2019

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
Copy link

Codeguyross commented May 3, 2019

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
Copy link

xinnyuann commented Jan 31, 2022

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 ('DiGraph' object has no attribute 'node' #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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests