While in my virtual environment, i'm trying to perform 'pip install .' with a setup.py such as :
from setuptools import setup
import pbr
... some functions ...
setup(
name='example',
setup_requires=['pbr'],
py_modules=['example'],
entry_points='''
[console_scripts]
example=example:main
''',
)
The thing is that i get the following error ImportError: No module named pbr
This seems quite legit as i didn't install pbr in my virtual environment BUT i thought that specifying 'setup_requires' would do the trick ... :/
Does someone understand why this does not work and knows how to fix it ? :)
The script does import pbr before running setup() so setup() was not given a chance to install pbr.
The fix is to not import pbr before running setup(). See https://docs.openstack.org/pbr/latest/user/using.html:
#!/usr/bin/env python
from setuptools import setup
setup(
setup_requires=['pbr'],
pbr=True,
)
Related
I'm currently creating a python library and need to use the 'find_namespace_packages' from the 'setuptools' package. However python throwing out the following ImportError message whenever it runs:
ImportError: cannot import name 'find_namespace_packages' from 'setuptools'
However it has no trouble importing the other functions from 'setuptools' like 'setup' and 'find_packages'.
How do I troubleshoot it?
I have uninstalled and reinstalled 'setuptools' multiple times already and updated Spyder and Anaconda.
Also here is a sample of my code:
from setuptools import setup, find_namespace_packages
setup(
name="sample",
version="0.0.1",
packages=find_namespace_packages()
)
I am currently using Python 3.7.5 and setuptools is on version 49.6.0
As mentioned in the question's comments, the solution is to run
pip install -U setuptools
And afterwards retry installing all the packages, e.g.
pip install -e .
I use python click package and setuptools to create a simple command line.
And I work in a pipenv virtualenv.
My working directory is like this:
jkt/scripts/app.py
And my setup.py is like this:
from setuptools import setup, find_packages
setup(
name='jkt',
version='0.1',
packages=find_packages(),
include_package_data=True,
entry_points='''
[console_scripts]
jktool=jkt.scripts.app:my_function
''',
)
Then I run the command
pip install --editable .
And run jktool to execute my_function but I get the error:
ModuleNotFoundError No module named 'jkt'.
But when the app.py in jkt directory I can run my function
setup(
name='app',
version='0.1',
py_modules=['app'],
entry_points='''
[console_scripts]
app=app:jktools
''',
)
After I run pip install -e . I can use app command to run my function.
As I mentioned, I can't reproduce your error (Python 3.7 with modern pip seems to work just fine), but there are a couple things that could potentially be going wrong on older versions.
Since it doesn't look like you put __init__.py files in your subdirectories, find_packages doesn't actually find any packages at all (python3 -c 'from setuptools import find_packages; print(find_packages()) prints the empty list, []). You can fix this in one of three ways:
Create empty __init__.py files to explicitly mark those folders as package folders; on a UNIX-like system, touch jkt/__init__.py and touch jkt/scripts/__init__.py is enough to create them
Python 3.3+ only: (also requires modern setuptools so pip install --upgrade setuptools might be necessary) Replace your use of find_packages with find_namespace_packages (which recognizes Python 3 era implicit namespace packages).
Just get rid of find_packages entirely and list the packages directly, e.g. replace packages=find_packages(), with packages=['jkt', 'jkt.scripts'],
Options #2 only works on Python 3.3+, so if your package is intended to work on older versions of Python, go with option #1 or #3.
I'm trying to prepare setup.py that will install all necessary dependencies, including google-cloud-pubsub. However, python setup.py install fails with
pkg_resources.UnknownExtra: googleapis-common-protos 1.6.0b6 has no such extra feature 'grpc'
The weird thing is that I can install those dependencies through pip install in my virtualenv.
How can I fix it or get around it? I use Python 2.7.15.
Here's minimal configuration to reproduce the problem:
setup.py
from setuptools import setup
setup(
name='example',
install_requires=['google-cloud-pubsub']
)
In your setup.py use the following:
from setuptools import setup
setup(
name='example',
install_requires=['google-cloud-pubsub', 'googleapis-common-protos==1.5.3']
)
That seems to get around it
I'm building a python package which requires pywin32.
Adding pywin32 as a dependency doesn't work seamlessly, since it has a postinstall script which the user must run themselves.
Adding pypiwin32 as a dependency doesn't work because my package won't play nice with other packages which do require pywin32
I tried requiring both, but it turns out pywin32 and pypiwin32 can't coexist on the same python installation
Is there a way of specifying either pywin32 or pypiwin32 as a dependency? Or some other solution?
The adding pip install pywin32 as a post-install script works, but removes the install_requires command from setup. To fix this, add do_egg_install(self) rather than run in the classes
from setuptools import setup
from setuptools.command.develop import develop as _develop
from setuptools.command.install import install as _install
from subprocess import check_call
# PostDevelopCommand
class develop(_develop):
"""Post-installation for development mode."""
def run(self):
check_call("pip install pywin32")
develop.do_egg_install(self)
# PostInstallCommand
class install(_install):
"""Post-installation for installation mode."""
def run(self):
check_call("pip install pywin32")
develop.do_egg_install(self)
and insert cmdclass argument to setup() function in setup.py:
setup(
...
cmdclass={
'develop': develop,
'install': install,
},
...
)
I want to install py-yajl through setup.py like this.
from setuptools import setup, find_packages
here = os.path.abspath(os.path.dirname(__file__))
requires = [
'yajl',
]
setup(
...
install_requires=requires,
tests_require=requires,
...
)
But this setup.py has some errors.
>>> Creating a symlink for compilationg: includes/yajl -> yajl/src/api
error: SandboxViolation: symlink('../yajl/src/api', 'includes/yajl') {}
The package setup script has attempted to modify files on your system
that are not within the EasyInstall build area, and has been aborted.
This package cannot be safely installed by EasyInstall, and may not
support alternate installation locations even if you run its setup
script by hand. Please inform the package's author and the EasyInstall
maintainers to find out if a fix or workaround is available.
I know I can install yajl using pip.
If some config could be changed by setup.py to use pip, I will install yajl but I don't know how to do it.
Does someone have a good idea?