Hi !
I've tried to use a package I've created (named mypackage) on my main program (named collector). mypackage is defined with the setup.py below:
name = "mypackage"
[...]
packages = find_packages(),
include_package_data = True,
exclude_package_data = { '': ['README.md'] }
[...]
entry_points = {
'console_scripts': [
'my-package=mypack.mypack:main'
]
},
I want to use a little program present this package, which will normally be called as below on collector:
from mypack.common.prog import mylittleprogram
I've tried to install mypackage on a virtualenv, and then (re)installed my main program. Then I executed it, and there is the error I have:
Traceback (most recent call last):
from project.common.collector import collectArt
File "/root/project/lib/python3.5/site-packages/collector-0.1-py3.5.egg/project/common/collector.py", line 7, in <module>
ImportError: No module named 'mypack'
Also, when the virtualenv is activated, I've just tried to launch the entry-point named my-package:
Traceback (most recent call last):
File "/root/project/bin/my-package", line 11, in <module>
load_entry_point('mypackage==0.1.1', 'console_scripts', 'my-package')()
File "/root/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 560, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/root/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2648, in load_entry_point
return ep.load()
File "/root/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2302, in load
return self.resolve()
File "/root/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2308, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named 'mypack'
Note 1: I precise that I have the __init__.py on each folder of my package.
Note 2: the virtualenv folders are on the same folder as my main program.
How do I use mylittleprogram present on mypackage on my collector main program with virtualenv ? Did I made something wrong ?
Thank you :)
There is the issue, I had to install my package via the following command:
python setup.py develop
And then the package is recognized. This command has to be executed when the virtualenv is activated, and be executed on the directory of the package.
Hope this will help someone in the future !
Related
I want to install some python packages ( importlib_metadata threadpoolctl) from source. They have pyproject.toml setup.cfg files, but there's no setup.py file. So when I try to install them, they give the same errors:
Traceback (most recent call last):
File "utils/scanpypi", line 750, in <module>
main()
File "utils/scanpypi", line 698, in main
package.load_setup()
File "utils/scanpypi", line 300, in load_setup
s_file, s_path, s_desc = imp.find_module('setup', [self.tmp_extract])
File "/usr/lib/python3.8/imp.py", line 296, in find_module
raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named 'setup'
Can I get some help, pls?
Your package uses PEP517 rather than setuptools or distutils. Support for PEP517 was added to Buildroot in 2022.05. Make sure you have a recent Buildroot version and set PYTHON_FOO_SETUP_TYPE to flit. See the manual for details.
Support for PEP517 was not yet added to the scanpypi utility, but there's a patch for it.
I'm having a problem after having recently switched from python2 to python3.8.
This is my file setup (abridged):
package/
__init__.py
main.py
modules/
__init__.py
log.py
In python2 I used to import log.py into main.py with
import modules.log
When I do this in python3 and call main.py from the console with
python /path/to/package/main.py
everything works fine.
But then I create a python package from that and install it on my archlinux/raspberrypi and call the script via the console with
/usr/bin/package
it tells me
$ package
Traceback (most recent call last):
File "/usr/bin/package", line 11, in <module>
load_entry_point('package==3.1.1', 'console_scripts', 'package')()
File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2852, in load_entry_point
return ep.load()
File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2443, in load
return self.resolve()
File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2449, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/lib/python3.8/site-packages/package/main.py", line 5, in <module>
import modules.log
ModuleNotFoundError: No module named 'modules'
Any idea why it doesn't work? I suppose it looks in different places once installed as a package.
Thanks in advance
EDIT: I can successfully run the package when I change the imports to
from package.modules import log
But then it will only work if it is installed as a package. Running it from my IDE (where it is not installed as a package) will naturally result in the error
ModuleNotFoundError: No module named 'package'
You could use relative imports for intra-package references, e.g. for main.py referencing log.py it would be:
import .modules.log
There have been huge changes in import behavior between Python 2 and 3. Refer to The Conservative Python 3 Porting Guide: Importing
For local development purposes there is a nice option to install package as a symlink
pip install -e ./ --user
In that case it will keep your installed package up-to-date with source, while you will be able to use this package as usual.
You need to specify what is root of your source files to packaging utitlity.
I expectiong you have standard setup.py with your package definition.
Look at package_dir option
https://python.readthedocs.io/en/stable/distutils/examples.html
(Alternatively you can change PYTHONPATH in you ide configuration and use package.modules)
When I install a package 'python-brick-cinderclient-ext' from sources it works. But when I try to install it from .deb package that I've built, I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/brick_cinderclient_ext/__init__.py", line 30, in <module>
'brick-python-cinderclient-ext').version_string()
File "/usr/lib/python2.7/dist-packages/pbr/version.py", line 457, in version_string
return self.semantic_version().brief_string()
File "/usr/lib/python2.7/dist-packages/pbr/version.py", line 452, in semantic_version
self._semantic = self._get_version_from_pkg_resources()
File "/usr/lib/python2.7/dist-packages/pbr/version.py", line 439, in _get_version_from_pkg_resources
result_string = packaging.get_version(self.package)
File "/usr/lib/python2.7/dist-packages/pbr/packaging.py", line 668, in get_version
raise Exception("Versioning for this project requires either an sdist"
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. Are you sure that git is installed?
But when I've move the code in the same location that it installs with python setup.py install (from the /usr/lib/python2.7/dist-packages/ to /usr/local/lib/python2.7/dist-packages/) then it worked fine! Why is this happening?
The problem was in the wrong name for pbr.version module. There is brick-python-cinderclient-ext instead of python-brick-cinderclient-ext in the __init__.py file. So, it's a reason why pbr could not get the version of this package -> It's just could not find the version of such package in the egg.info. I've fixed it with the patch for __init__.py file with renaming brick-python-cinderclient-ext to python-brick-cinderclient-ext.
I am trying to build an installer for a sage script using setuptools. Here is what I have.
My setup.py file:
#!/usr/bin/env python2
from setuptools import setup
__name__ = 'sage-test'
__version__ = '0.0'
setup(name=__name__,
scripts=['sage-test'],
)
The sage-test file:
#!/usr/bin/env sage
from sage.all import GF
print(GF(5))
I now do ./setup.py build and ./setup.py install. When I try to run sage-test, I get the following error:
Traceback (most recent call last):
File "/usr/bin/sage-test", line 4, in <module>
__import__('pkg_resources').run_script('sage-test==0.0.0', 'sage-test')
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 517, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 1443, in run_script
exec(script_code, namespace, namespace)
File "/usr/lib/python2.7/site-packages/sage_test-0.0.0-py2.7.egg/EGG-INFO/scripts/sage-test", line 3, in <module>
__requires__ = 'sage-test==0.0.0'
ImportError: No module named sage.all
Any ideas how to get this to work? (Note that I can run ./sage-test within the current directory and everything works.)
This may not help, but this looks suspicious.
/usr/lib/python2.7/
Maybe you need to do everything within sage -sh - I wouldn't be surprised if there was some env var that was not set up properly. I don't know exactly why but maybe it's picking up your system Python somehow.
I'm trying to get a work project that I git-cloned from work (used in numerous other places, I know the project works fine) to run on my MacBook. I installed Django (via sudo python setup.py install), as well as MySQL, the Python MySQL wrapper, and also virtualenv with virtualenvwrapper.
After creating a virtualenv for my project (virtualenv is created fine), and doing a pip install for the project requirements (all of which install into the proper virtualenv directory), an attempt to do a runserver command spits out the following:
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 436, in execute_manager
setup_environ(settings_mod)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 419, in setup_environ
project_module = import_module(project_name)
File "/Library/Python/2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named website-backend
First try to import this library from python or ./manage.py shell.
If that fails import sys and check if your lib is in sys path print sys.path