I have a library with the following setup.py:
from setuptools import setup
from mylib import __version__
requirements = ['paramiko']
tests_require = ['pytest']
def main():
setup(
name='mypackage',
description='A collection of utilities',
url='http://example.net',
version=__version__,
author='Me Me',
author_email='me#me.net',
packages=['mylib'],
zip_safe=False,
install_requires=requirements,
tests_require=tests_require,
)
if __name__ == '__main__':
main()
I have released this package to an internal devpi server. Whenever I try to install it, I get:
» pip install mypackage
Looking in indexes: http://devpi.mine/myuser/dev/+simple/
Collecting mypackage
Downloading http://devpi.mine/myuser/dev/+f/a8c/c05e3a49de4fe/mypackage-0.0.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-ee238ja7/mypackage/setup.py", line 3, in <module>
from mypackage import __version__
File "/tmp/pip-install-ee238ja7/mypackage/mylib/__init__.py", line 3, in <module>
from .storage_host import StoraHostType
File "/tmp/pip-install-ee238ja7/mypackage/mylib/storage_host.py", line 5, in <module>
from .ssh import SSH
File "/tmp/pip-install-ee238ja7/mypackage/mylib/ssh.py", line 5, in <module>
import paramiko
ModuleNotFoundError: No module named 'paramiko'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-ee238ja7/mypackage/
Why is pip not installing the requirements listed in install_requires, in setup.py?
That is because you are referring your package before setup has been executed.
Pip need to first touch setup(...) to do everything. But before it, you from mylib import __version__. So setup doesn't execute at all.
Related
When executing python3 (Python 3.6.8) script on a local directory, it works well, but when running sbatch job in slurm, complains about certifi.
python3 -m pip install certifi
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: certifi in /usr/local/lib/python3.6/site-packages (2020.12.5)
After adding to the python code this:
import sys
import os
sys.path.append(os.getcwd())
or this:
import sys
import os
module_path = os.path.abspath(os.getcwd())
if module_path not in sys.path:
sys.path.append(module_path)
the same error occurs. It seems that certifi is installed.
pip show certifi
Name: certifi
Version: 2020.12.5
Summary: Python package for providing Mozilla's CA Bundle.
Home-page: https://certifiio.readthedocs.io/en/latest/
Author: Kenneth Reitz
Author-email: me#kennethreitz.com
License: MPL-2.0
Location: /usr/local/lib/python3.6/site-packages
Requires:
Required-by: requests
The error after running python code (without having the line 'import certifi' in python code):
Traceback (most recent call last):
File "/home/username/test/test.py", line 19, in <module>
from textattack.augmentation import WordNetAugmenter, EmbeddingAugmenter, EasyDataAugmenter, CharSwapAugmenter
File "/home/username/.local/lib/python3.6/site-packages/textattack/__init__.py", line 12, in <module>
from . import (
File "/home/username/.local/lib/python3.6/site-packages/textattack/attack_recipes/__init__.py", line 21, in <module>
from .attack_recipe import AttackRecipe
File "/home/username/.local/lib/python3.6/site-packages/textattack/attack_recipes/attack_recipe.py", line 9, in <module>
from textattack.shared import Attack
File "/home/username/.local/lib/python3.6/site-packages/textattack/shared/__init__.py", line 11, in <module>
from . import utils
File "/home/username/.local/lib/python3.6/site-packages/textattack/shared/utils/__init__.py", line 1, in <module>
from .install import *
File "/home/username/.local/lib/python3.6/site-packages/textattack/shared/utils/install.py", line 9, in <module>
import requests
File "/home/username/.local/lib/python3.6/site-packages/requests/__init__.py", line 118, in <module>
from . import utils
File "/home/username/.local/lib/python3.6/site-packages/requests/utils.py", line 25, in <module>
from . import certs
File "/home/username/.local/lib/python3.6/site-packages/requests/certs.py", line 15, in <module>
from certifi import where
ModuleNotFoundError: No module named 'certifi'
The error (with having the line 'import certifi' in python code):
Traceback (most recent call last):
File "/home/username/projecttest_LR_attack/LR_attack.py", line 17, in <module>
import certifi
ModuleNotFoundError: No module named 'certifi'
What could be the solution to the issue?
for anyone on MacOS and already ran pip install certifi and still doesn't work
Go to your applications folder > find your python version folder -> double click on the file Install Certificates.command inside the python folder to install the certificate.
wait for it to complete the installation
After that, you can try running your code with requests package again
Are the same modules installed on the compute nodes as locally? You may need to check with the Slurm admins.
This could mean that /usr/local/lib/python3.6/site-packages/ is not your PYTHONPATH environment variable that sbatch job in slurm has access to. You can either add it or append it during runtime:
import sys
sys.path.append('/usr/local/lib/python3.6/site-packages/')
pip install certifi
Try this command on the CLI
I am trying to create a module using setuptools. I installed setuptools and wrote a small piece of code as TestFunction.py:
def function(test):
print(test);
function("hello World")
and created a setup.py file with the below instruction:
from setuptools import setup
setup(
name='TestFunction.py',
version='1.0',
description='this is a python distribution',
py_module=['TestFunction'],)
Now i am running python3 setup.py sdist and getting the below error. My os is ubuntu 18. Much appreciated.
Original exception was:
Traceback (most recent call last):
File "setup.py", line 1, in <module>
from setuptools import setup, find_packages
File "/home/jeet/.local/lib/python3.6/site-packages/setuptools/__init__.py", line 6, in <module>
import distutils.core
File "/usr/lib/python3.6/distutils/core.py", line 16, in <module>
from distutils.dist import Distribution
File "/usr/lib/python3.6/distutils/dist.py", line 18, in <module>
from distutils.fancy_getopt import FancyGetopt, translate_longopt
File "/usr/lib/python3.6/distutils/fancy_getopt.py", line 373, in <module>
WS_TRANS = {ord(_wschar) : ' ' for _wschar in string.whitespace}
AttributeError: module 'string' has no attribute 'whitespace'
It seems you have a file string.py that isn't a module from the standard library but your own module or script. Rename it so it doesn't overshadow the standard module; don't forget to remove string.pyc file; for python 3.6 it's in __pycache__ directory.
I changed your code because you have an indentation formatting error. Rest of your code works fine.
copy and try this:
test_module.py
def function1(test):
print(test);
setup.py
from setuptools import setup
setup(
name='test_module.py',
version='1.0',
description='this is a python distribution',
py_module=['test_module'],)
usage:
python setup.py install
use your function:
from test_module import function1
function1("hello stackoverflow")
output:
hello stackoverflow
I am trying to build a program called dnsrep in Python, I am using setuptools so that I can call the dnsrep module without using the command python dnsrep. The setup.py script I wrote is given below:
from setuptools import setup, find_packages
setup(
name='dnsrep',
version='0.1',
description='Program that gives a reputation score to url\'s\n.',
entry_points = {
'console_scripts': ['dnsrep = dnsrep:main']
},
zip_safe=True,
)
I install the module by using the command:
python setup.py install
My module gets registered but when I run it I get the error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/bin/dnsrep", line 9, in <module>
load_entry_point('dnsrep==0.1', 'console_scripts', 'dnsrep')()
File "build/bdist.macosx-10.6-intel/egg/pkg_resources/__init__.py", line 521, in load_entry_point
File "build/bdist.macosx-10.6-intel/egg/pkg_resources/__init__.py", line 2632, in load_entry_point
File "build/bdist.macosx-10.6-intel/egg/pkg_resources/__init__.py", line 2312, in load
File "build/bdist.macosx-10.6-intel/egg/pkg_resources/__init__.py", line 2318, in resolve
ImportError: No module named dnsrep
You have to install your python script, before you can call it via your defined entry point
This is my dummy project:
dnsrep/
├── dnsrep.py
└── setup.py
This is how setup.py looks like:
from setuptools import setup
setup(
name='dnsrep',
version='0.1',
description='Program that gives a reputation score to url\'s\n.',
py_modules=['dnsrep'],
entry_points = {
'console_scripts': ['dnsrep = dnsrep:main']
},
zip_safe=True,
)
Note the argument py_modules=['dnsrep'], which installs dnsrep.py as a new module.
Finally, this is my dummy implementation of dnsrep.py:
from __future__ import print_function
def main():
print("Hey, it works!")
After installing, everything works as expected and $ dnsrep prints: Hey, it works!
I created my first package. When I try to install it with pip in a newly created virtualenv I get an error indicating that libs cannot be imported, yet they are added to the install_requires field in setup.py. If I do it outside a vierualenv, all is ok.
My setup.py is here: https://github.com/tdi/pyPEPA/blob/dev/setup.py
To reproduce the error:
mkvirtualenv something -p /usr/bin/python3
workon something
pip install pypepa
.
Downloading/unpacking pypepa
Running setup.py egg_info for package pypepa
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/home/tdi/.virtualenvs/koza/build/pypepa/setup.py", line 3, in <module>
import pypepa
File "./pypepa/__init__.py", line 6, in <module>
from pypepa.pepa_model import PEPAModel
File "./pypepa/pepa_model.py", line 6, in <module>
from pypepa.parsing.parser import PEPAParser
File "./pypepa/parsing/parser.py", line 5, in <module>
from pyparsing import Word, Literal, alphas, alphanums, nums, Combine, Optional, ZeroOrMore, Forward, restOfLine
ImportError: No module named 'pyparsing'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/home/tdi/.virtualenvs/koza/build/pypepa/setup.py", line 3, in <module>
import pypepa
File "./pypepa/__init__.py", line 6, in <module>
from pypepa.pepa_model import PEPAModel
File "./pypepa/pepa_model.py", line 6, in <module>
from pypepa.parsing.parser import PEPAParser
File "./pypepa/parsing/parser.py", line 5, in <module>
from pyparsing import Word, Literal, alphas, alphanums, nums, Combine, Optional, ZeroOrMore, Forward, restOfLine
ImportError: No module named 'pyparsing'
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /home/tdi/.virtualenvs/koza/build/pypepa
Storing complete log in /home/tdi/.pip/pip.log
Your setup script imports pypepa which imports pypepa.pepa_model which imports pyparsing, but pyparsing is not installed yet (we haven’t even finished running the setup script to know what the dependencies are). The solution is to repeat the version number in pypepa and setup.py (so you can remove the import), or not import PEPAModel in __init__.py.
Python3 uses distutils and setup() will take a requires keyword arguments. From the docs:
Dependencies on other Python modules and packages can be specified by supplying the requires keyword argument to setup().
Change install_requires to requires in you setup.py script.
I installed Python3.3 as non-root user, and use pip from python virtualenv to install beaver, a python module depends on python-daemon. However the install failure because python-daemon can not be installed.
(py_virtual)[infra#sulog01 beaver-master]$ pip install beaver==22
Downloading/unpacking beaver==22
Downloading Beaver-22.tar.gz (40kB): 40kB downloaded
Running setup.py egg_info for package beaver
Downloading/unpacking pika>=0.9.5 (from beaver==22)
Downloading pika-0.9.9.tar.gz (56kB): 56kB downloaded
Running setup.py egg_info for package pika
Downloading/unpacking python-daemon>=1.5.2 (from beaver==22)
Downloading python-daemon-1.6.tar.gz (41kB): 41kB downloaded
Running setup.py egg_info for package python-daemon
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/home/infra/logstash/beaver_Python/beaver-
master/py_virtual/build/python-daemon/setup.py", line 22, in
<module>main_module = __import__(main_module_name,
fromlist=['version'])
File "./daemon/__init__.py", line 42, in <module>
from . import version
File "./daemon/version/__init__.py", line 16, in <module>
from .version_info import version_info
File "./daemon/version/version_info.py", line 21
print 'revision: %(revno)d' % version_info
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/home/infra/logstash/beaver_Python/beaver-master/
py_virtual/build/python-daemon/setup.py", line 22, in <module>
main_module = __import__(main_module_name, fromlist=['version'])
File "./daemon/__init__.py", line 42, in <module>
from . import version
File "./daemon/version/__init__.py", line 16, in <module>
from .version_info import version_info
File "./daemon/version/version_info.py", line 21
print 'revision: %(revno)d' % version_info
^
SyntaxError: invalid syntax
----------------------------------------
Command python setup.py egg_info failed with error code 1 in
/home/infra/logstash/beaver_Python/beaver-master/py_virtual/
build/python-daemon
Storing complete log in /home/infra/.pip/pip.log
Do I need to install anything else before install python-daemon? Or is this issue with Python3.3 itself?
Looks like beaver and python-daemon don't support Python 3 at this point. You'll have to use Python 2.x.