Issue
I'd like to make a wheel binary distribution, intstall it and then import it in python. My steps are
- I first create the wheel:
python ./my_package/setup.py bdist_wheel
- I install the wheel:
pip install ./dist/*.whl
- I try to import the package:
python -c"import my_package"
This leads to the error:
ImportError: No module named 'my_package'
Also, when I do pip list
, the my_package
is listed.
However, when I run which my_packge
, nothing is shown.
When I run pip install ./my_package/
everything works as expected.
How would I correctly build and install a wheel?
python version 3.5 pip version 10.1 wheel version 0.31.1
UPDATE:
When I look at the files inside my_package-1.0.0.dist-info, there is an unexpected entry in top_level.txt
. It is the name of the folder where I ran
python ./my_package/setup.py bdist_wheel
in. I believe my setup.py
is broken.
UPDATE WITH REGARDS TO ACCEPTED ANSWER:
I accepted the answer below. Yet, I think it is better to simply cd
into the package directory. Changing to a different directory as suggested below leads to unexpected behavior when using the -d
flag, i.e. the target directory where to save the wheel. This would be relative to the directory specified in the setup.py file.
Solution
If you need to execute the setup script from another directory, ensure you are entering the project dir in the script.
from setuptools import setup
root = os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))
os.chdir(root)
# or using pathlib (Python>=3.4):
import patlib
root = pathlib.Path(__file__).parent
os.chdir(str(root))
setup(...)
Answered By - hoefling
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.