PrincetonUniversity / SPEC

The Stepped-Pressure Equilibrium Code, an advanced MRxMHD equilibrium solver.
https://princetonuniversity.github.io/SPEC/
GNU General Public License v3.0
24 stars 4 forks source link

import py_spec fails when using pypi #121

Closed landreman closed 3 years ago

landreman commented 3 years ago

When py_spec is installed from pypi using pip install py_spec, and you try to import py_spec in python, the following error occurs:

>>> import py_spec
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mattland/opt/miniconda3/lib/python3.8/site-packages/py_spec/__init__.py", line 4, in <module>
    from . import ci
  ImportError: cannot import name 'ci' from partially initialized module 'py_spec' (most likely due to a circular import) (/Users/mattland/opt/miniconda3/lib/python3.8/site-packages/py_spec/__init__.py)

I get this error both on my macbook using conda, and also on the Github Actions Ubuntu system. The error does not occur when installing py_spec from a copy of the repository using pip install -e .

Also the README says that py_spec can be installed by

pip install git+https://github.com/PrincetonUniversity/SPEC/tree/master/Utilities/pythontools

but this seems to give an error:

  fatal: repository 'https://github.com/PrincetonUniversity/SPEC/tree/master/Utilities/pythontools/' not found
ERROR: Command errored out with exit status 128: git clone -q https://github.com/PrincetonUniversity/SPEC/tree/master/Utilities/pythontools /private/var/folders/_2/t14gsms50v1dmfz95bz32hk00000gn/T/pip-req-build-eqtrvrpm Check the logs for full command output.

Looking at this link, a variant that does work on my end is

pip install "git+https://github.com/PrincetonUniversity/SPEC.git#egg=SPEC&subdirectory=Utilities/pythontools

If py_spec is installed this way, the cannot import name 'ci' error still occurs.

zhucaoxiang commented 3 years ago

@landreman Good catch. I was trying to fix the issues (https://github.com/PrincetonUniversity/SPEC/compare/pypi?expand=1). But now I got the weird error of setup.py: error: unrecognized arguments: --egg-base. I have no idea why the new changes lead to such an error and I didn't find anything related to this error online.

Does anyone have a clue?


$ pip install -e .
Obtaining file:///Users/caoxiang/Documents/Codes/SPEC/Utilities/pythontools
    ERROR: Command errored out with exit status 2:
     command: /opt/anaconda3/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/Users/caoxiang/Documents/Codes/SPEC/Utilities/pythontools/setup.py'"'"'; __file__='"'"'/Users/caoxiang/Documents/Codes/SPEC/Utilities/pythontools/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/c8/634lbtm911lc1bg5bvch5tdw0000gn/T/pip-pip-egg-info-c205dwd8
         cwd: /Users/caoxiang/Documents/Codes/SPEC/Utilities/pythontools/
    Complete output (2 lines):
    usage: setup.py [-h] [-t TOL] filename reference
    setup.py: error: unrecognized arguments: --egg-base
    ----------------------------------------
ERROR: Command errored out with exit status 2: python setup.py egg_info Check the logs for full command output.
``
landreman commented 3 years ago

I unfortunately don't have any ideas about the unrecognized arguments: --egg-base error.

In Utilities/pythontools/py_spec/ci there is a file __init.py rather than __init__.py. Is this a mistake?

zhucaoxiang commented 3 years ago

@landreman That solves the problem. I think I fixed it and it now works in the pypi branch. I will create a pull request now.

smiet commented 3 years ago

@landreman, is the issue resolved for you? If so then I will close it.

Great catch, thanks for finding it, the misnamed file was likely a typo on my part when I created the file, but the import still succeeded on my system because the folder was hard-coded into my pythonpath.

landreman commented 3 years ago

Yes, the issue is resolved for me.