I believe this question was asked before but I'm still a little stuck. I'm trying to install a Python package that has some data files with subdirectories. Here's my setup:
setup.py
src/
mypkg/
__init__.py
module.py
data/
tables.dat
spoons.dat
sub/
forks.dat
Following the docs I tried to add:
setup(...,
packages=['mypkg'],
package_dir={'mypkg': 'src/mypkg'},
package_data={'mypkg': ['data/*.dat', 'data/sub/*.dat']},
)
I install the module with python setup.py install (though eventually I'll use python setup.py sdist upload to upload the package to pypi so others can pip install the module.
After running the python setup.py install command, to find the module location, I then import mypkg and print(mypkg.__file__). In the package directory, however, I can see data but not data/sub. Does anyone know what I'm missing? Any help is greatly appreciated!
Ah, it turns out the above works fine!
To install the module to my site-packages/mypkg location, I just had to use: python setup.py sdist and then pip install dist/mypkg-0.0.1.tar.gz.
Then my data files were in site-packages/mypkg.
I had the same issue, in my case the problem was the package was installed and when executing
pip install .
in my local it didn't reinstall, so the packages weren't included.
Uninstall before install was the key for me
Related
I have written a python package mypackage , hosted on github, that I now want to install as a dependency to another project (specifically branch branch).
I can build it locally using setuptools and a pyproject.toml file by running python3 -m pip install . at the top of mypackage/ and can then successfully import it into python.
I pushed this to github and now try to install it using
python3 -m pip install "git+https://github.com/mygituser/mypackage.git#branch"
This runs without warning, and if I then run python3 -m pip list I can see mypackage listed there. However, if I enter python and run import mypackage I get the error ModuleNotFoundError: No module named 'mypackage'.
Comparing the verbose outputs I can see that for the local install after installing the dependencies I get
running bdist_wheel
running build
running build_py
running egg_info
writing mypackage/mypackage.egg-info/PKG-INFO
writing dependency_links to mypackage/mypackage.egg-info/dependency_links.txt
...
...
etc. which is absent for the github build process (this just ends after dependencies are installed).
Am I missing a setting in pyproject.toml or somewhere to tell it to build a wheel so I can import mypackage it in python?
I have tried appending with #egg=mypackage and adding wheel to the build dependencies, but none of this has worked.
TIA
In addition to the changes you made to your pyprojcet.toml file here: https://github.com/jatkinson1000/archeryutils/commit/f5fb491aa37961a65796ce4be3616d8be23548ed
You also need to include a __init__.py file in your round_data_files folder so it gets included in the package install.
https://github.com/jatkinson1000/archeryutils/pull/9
I'm trying to install openpyxl and I haven't the clue how to install it. I have my C:\Python27...but what directory do I put it in? FYI, I'm a complete noob to modules and what not...I appreciate your help.
I have put in the lib and libs directory of python and try installing it to no avail. Here is a link to the site I got my download... http://pythonhosted.org/openpyxl/.
Basically, I extracted the file and move it to the lib directory. However, I cannot import it.
There is a setup.py script provided. Typically you run:
python setup.py install
From the directory were you've downloaded the library, and it gets installed automatically.
Consider also more convenient tools that manage installing Python libraries in general like pip or easy_install mentioned in other answers and comments.
It's even easier when the package is on the Python Package Index (PyPI). Just install pip and use it to download and install the package and all its dependencies.
https://pypi.python.org/pypi/pip
I like to figure out the myth behind Python's namespace packages by setuptools, and here is what I did test.
Make a virtual environment by virtualenv.
Find a namespaced package on PyPI.
Install that package by pip install.
Check the installed file hierarchy.
The package I played with is zope.interface and it worked well with the following file hierarchy on my virtualenv:
~virenv/.../site-packages/zope.interface-3.8.0-py2.6-nspkg.pth
/zope.interface-3.8.0-py2.6.egg-info/
/zope/
/interface/
/...
Everything looked fine and I love the way zope.interface got installed as a real namespaced package (under folder zope).
Then, I did another test and that's the question I would like to ask for your help. I downloaded the tared zope.interface source file. I liked to play it manually again
Make a virtual environment by virtualenv.
Untar the zope.interface into somewhere.
Install the package by python setup.py install.
Go check what happened in site-packages.
The site-packages looks like this:
~virenv/../site-packages/zope.interface-...egg/
/zope/
/__init__.py
/interface/
/EGG-INFO/
Q. How come I can't get the exactly result to pip install by manually python setup.py install?
pip uses setup.py internally. It just passes additional option to it. To reproduce what pip is doing, execute
python setup.py install --single-version-externally-managed
You can also run pip -vv to see exactly which commands are run.
Q. How come I can't get the exactly result to pip install by manually
python setup.py install?
Because pip and setup.py are two different pieces of software.
pip is not advertised as providing identical behaviour to setup.py, nor vice versa.
If you want the behaviour of pip, use pip; if you want the behaviour of setup.py, use setup.py.
I have made a distribution of my python package with the following setup.py
#!/usr/bin/env python
from setuptools import setup
setup(name='mypackagename',
version='0.1',
description='Tool ....',
author='Peter Smit',
author_email='lala#lala.com',
packages=['mypackagename'],
package_dir={'': 'src'},
install_requires=['boto'],
entry_points = dict(console_scripts=[
'mypackagenamescript = mypackagename.launcher:run',
])
)
I created an egg of this with python setup.py bdist_egg.
Trying to install it now with pip gives the following error:
bin/pip install mypackagename-0.1-py2.6.egg
Downloading/unpacking mypackagename-0.1-py2.6.egg
Could not find any downloads that satisfy the requirement mypackagename-0.1- py2.6.egg
No distributions at all found for mypackagename-0.1-py2.6.egg
Storing complete log in /home/peter/.pip/pip.log
The mentioned log files showed that it tries to download the package from pypi, where it obviously does not exist.
What did I do wrong? How can I install this egg of mine plus it's dependencies?
why not using setuptools easy_install?
easy_install mypackagename-0.1-py2.6.egg
If you want to work with eggs that's the way.
pip cannot install from eggs.
If you want your package to be available on PyPI, you need to register and account there and upload it. You can then simply say pip install myproject. It will search PyPI, find it, download and install it.
If you have your setup.py ready and want to install your application locally, all you need to do is to say python setup.py install. You don't need to use pip or easy_install.
The hitchhikers guide to packaging contains details on all these things. It should make things clear.
Pip cannot install eggs. IMHO that is a serious lack. I would suggest you to try out Pyg. Just download the get-pyg.py script and execute it:
$ curl -O https://raw.github.com/rubik/pyg/master/get-pyg.py
$ python get-pyg.py
Retrieving archive from ... etc.
Note: As an alternative, you can install it via easy_install or pip.
Then you can use it:
$ pyg install mypackagename-0.1-py2.6.egg
Pyg supports virtualenv too.
rubik
According to setuptools documentation, setup.py develop is supposed to create the egg-link file and update easy_install.pth when installing into site-packages folder. However, in my case it's only creating the egg-link file. How does setuptools decide if it needs to update easy_install.pth?
Some more info:
It works when I have setuptools 0.6c7 installed as a folder under site-packages. But when I use setuptools 0.6c9 installed as a zipped egg, it does not work.
Reinstall setuptools with the command easy_install --always-unzip --upgrade setuptools. If that fixes it then the zipping was the problem.
I'd try to debug it with pdb. The issue is most likely with the easy install's method check_site_dir, which seeks for easy-install.pth.