In my setup.py file, I can declare that PyUserInput is a requirement for my project (Python 3), but a prerequisite for PyUserInput on Linux is the Python module Xlib.
This is the relevant part of my setup.py file:
setup(...
install_requires=['requests', 'nose', 'PyUserInput'],
...
)
I tried putting Python-Xlib and Xlib into the install_requires argument, which didn't work since setuptools couldn't resolve those names automatically.
What do I need to do? I would prefer to be able to have the single command sudo python3 setup.py install handle installing all of the prerequisites for my package and not have to ask the user to manually install some prerequisites.
Using pip search xlib, I found that there was a package named python3-xlib. Adding python3-xlib as a requirement in setup.py was sufficient.
Related
I am working on a setup.py file for a Python package. I want to include the package "rdkit" among the "install_requires" dependencies of my package. However, that does not work, as rdkit cannot be directly pip-installed. My preferred method in this case is to use conda (https://anaconda.org/rdkit/rdkit).
Is there a way to automate the installation (or upgrade) if required of a package using conda in a setup.py file, similarly to what install_requires does for pip-installable dependencies?
Thank you very much for your help
setup(
...
install_requires=[
'numpy >= 1.8.0',
'scipy >= 1.6.1',
],
)
Is there a way to automate the installation (or upgrade) if required of a package using conda in a setup.py file…?
Nop, no way. setup.py is intended for python setup.py install or pip install and it doesn't know anything about conda.
Perhaps it should be solved the other way — starting from conda that then calls pip install to install pip-installable packages.
Trying to test editable installs out and I'm not sure how to interpret the results.
I intentionally made a typo in the egg= portion but it was still able to locate the egg without any help from me:
root#6be8ee41b6c9:/# pip3 install -e git+https://gitlab.com/jame/clientapp.git
Could not detect requirement name for 'git+https://gitlab.com/jame/clientapp.git', please specify one with #egg=your_package_name
root#6be8ee41b6c9:/# pip3 install -e git+https://gitlab.com/jame/clientapp.git#egg=
Could not detect requirement name for 'git+https://gitlab.com/jame/clientapp.git#egg=', please specify one with #egg=your_package_name
root#6be8ee41b6c9:/# pip3 install -e git+https://gitlab.com/jame/clientapp.git#egg=e
Obtaining e from git+https://gitlab.com/jame/clientapp.git#egg=e
Cloning https://gitlab.com/jame/clientapp.git to /src/e
Running setup.py (path:/src/e/setup.py) egg_info for package e produced metadata for project name clientapp. Fix your #egg=e fragments.
Installing collected packages: clientapp
Found existing installation: ClientApp 0.7
Can't uninstall 'ClientApp'. No files were found to uninstall.
Running setup.py develop for clientapp
Successfully installed clientapp
root#6be8ee41b6c9:/# pip3 freeze
asn1crypto==0.24.0
-e git+https://gitlab.com/jame/clientapp.git#5158712c426ce74613215e61cab8c21c7064105c#egg=ClientApp
cryptography==2.6.1
entrypoints==0.3
keyring==17.1.1
keyrings.alt==3.1.1
pycrypto==2.6.1
PyGObject==3.30.4
pyxdg==0.25
SecretStorage==2.3.1
six==1.12.0
So if I could mess the egg name up so bad, why is it considered an error to either leave it blank or set to something empty
Hard to answer, maybe raise this as an issue on pip's bug tracker and get an accurate answer from the developers themselves.
My guess, the egg name matters if the project is a dependency of another project. For example in a case where one wants to install A from PyPI and Z from git, but Z is a dependency of A.
pip install 'A' 'git+https://example.local/Z.git#egg=Z'
egg= is the name that's used when uninstalling unpackaged libraries that's installed from a VCS repository, and the name that's used by the dependency resolver when searching for dependant packages.
If you don't care about those two use cases, they can essentially be set to anything.
it found the egg via setup.py
It didn't find the egg via setup.py, pip found the setup.py and set the egg name for the setup.py install to whatever you specified. When you're installing from a VCS, there is no package, so there's no egg name configured, egg= configures the installation as if it has been installed with a package with that egg name.
I want to find a way to make my package development and use as automatic as possible.
Some of my package's dependencies are self-developed packages which are to be found in a git repository.
When I do pip freeze, it lists these git dependencies like so:
pandas==0.24.1
...
-e git+https://my/repo.git#ffffffffffffffffffffffffffffffffffffffff#egg=mydependency
Since I want to avoid copy-pasting, I do the following to include dependencies in setup.py:
with open("requirements.txt", "r") as f:
install_requires = f.read().splitlines()
setuptools.setup(
...
install_requires=install_requires,
)
(I produce requirements.txt via pip freeze > requirements.txt)
Then, when I try to install the package that has the setup.py described above, I get this error:
$ pip install .
Processing /path/to/pkg
Complete output from command python setup.py egg_info:
error in pkg setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'-e git+h'"
What am I doing wrong? Am I missing some important option of pip freeze when creating my requirements.txt? Am I misunderstanding the whole idea/process of pip and setuptools in the first place? Or is that idea flawed?
The only fix I can come up with is as ugly as introducing dependencies manually into setup.py's install_requires argument. Or maybe that's just the right way to do things?
The problematic dependency should not be published and needs to be installed from git.
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.