Python package seems to ignore my requirements - python

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.

Related

Python build_ext cause ImportError

I have a some python packages code with C and Cython extensions. When i try to build them, i get an ImportError. For example, output for opensource package pydatastructs (https://github.com/codezonediitj/pydatastructs).
C:\Users\Me\Projects\pydatastructs> py setup.py build_ext --inplace
Traceback (most recent call last):
File "C:\Users\Max\Projects\pydatastructs\setup.py", line 2, in <module>
from pydatastructs import linear_data_structures
File "C:\Users\Max\Projects\pydatastructs\pydatastructs\__init__.py", line 1, in <module>
from .linear_data_structures import *
File "C:\Users\Max\Projects\pydatastructs\pydatastructs\linear_data_structures\__init__.py", line 3, in <module>
from . import (
File "C:\Users\Max\Projects\pydatastructs\pydatastructs\linear_data_structures\arrays.py", line 4, in <module>
from pydatastructs.linear_data_structures._backend.cpp import _arrays
ImportError: cannot import name '_arrays' from 'pydatastructs.linear_data_structures._backend.cpp' (C:\Users\Max\Projects\pydatastructs\pydatastructs\linear_data_structures\_backend\cpp\__init__.py)
I guess python tries to import module which is not built yet, but i can't build them.
I tried to use pip install . but output is the same as above. It is possible to comment all import from extensions then build them and it works but this approach is very inconvenient especially in large projects with many extensions.

Dependencies are not installed by pip

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.

failed to install hashlib in python3.5 - error code 1

I am trying to install hashlib on my mac. pip doesn't work, and easy_install also does not work.
Here is the error:
Collecting hashlib
Using cached hashlib-20081119.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/setuptools/__init__.py", line 12, in <module>
import setuptools.version
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/setuptools/version.py", line 1, in <module>
import pkg_resources
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pkg_resources/__init__.py", line 36, in <module>
import email.parser
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/feedparser.py", line 27, in <module>
from email import message
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/message.py", line 16, in <module>
from email import utils
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/utils.py", line 28, in <module>
import random
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/random.py", line 45, in <module>
from hashlib import sha512 as _sha512
File "/private/var/folders/nw/flrm4y0d499fk5xr2ppxk4sr0000gn/T/pip-build-lv720o4k/hashlib/hashlib.py", line 80
raise ValueError, "unsupported hash type"
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/nw/flrm4y0d499fk5xr2ppxk4sr0000gn/T/pip-build-lv720o4k/hashlib/
Any further suggestions would be great. Thanks in advance!
I know this question is very old, but I stumbled upon it on Google because I had the same problem just now. In my case, I was working with an AWS Elastic Beanstalk, and my environment got that exact same cryptic error message about a syntax error inside hashlib.
For AWS, the trick is NOT including all your imports in the requirements.txt file, but only things you would normally have to pip install. That includes modules like hashlib, string, and random.
So for others who stumble upon this question: there is no need to install hashlib, just import it and you're ready to go!
sudo apt-get install libffi-dev g++ libssl-dev
via https://github.com/bigchaindb/bigchaindb/issues/24#issuecomment-183370814

python + how to install the module web.py

I installed on my XP machine the python version - 3.4.0
and now I want to install the web.py module
the installation is failed on print "var", var
I guess is because the missing "(" , ")"
but how to fix that?
C:\Python34\Scripts>pip install web.py
Downloading/unpacking web.py
Running setup.py (path:D:\DOCUME~1\uba\LOCALS~1\Temp\pip_build_uba\web.p
y\setup.py) egg_info for package web.py
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "D:\DOCUME~1\ubarih\LOCALS~1\Temp\pip_build_uba\web.py\setup.py",
line 6, in <module>
from web import __version__
File "D:\DOCUME~1\uba\LOCALS~1\Temp\pip_build_uba\web.py\web\__init_
_.py", line 14, in <module>
import utils, db, net, wsgi, http, webapi, httpserver, debugerror
File "C:\Python34\lib\site-packages\db\__init__.py", line 69
print "var", var
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "D:\DOCUME~1\uba\LOCALS~1\Temp\pip_build_uba\web.py\setup.py", line
6, in <module>
from web import __version__
File "D:\DOCUME~1\ubarih\LOCALS~1\Temp\pip_build_uba\web.py\web\__init__.py
", line 14, in <module>
import utils, db, net, wsgi, http, webapi, httpserver, debugerror
File "C:\Python34\lib\site-packages\db\__init__.py", line 69
print "var", var
^
SyntaxError: invalid syntax
----------------------------------------
Cleaning up...
You installed Python 3.4 on your machine, but web.py does not support Python3.X.
If you look at the source, you see that there is a branch in the git, but the migration seemed to be incomplete. (https://github.com/webpy/webpy/tree/python3/web).
There was also a discussion about the migration (https://groups.google.com/forum/#!topic/webpy/NvDqKEEEMEI).
Install the development branch
You can try this branch by downloading the source from github
(https://github.com/webpy/webpy/archive/python3.zip). After you downloaded the file, extract it and run the setup-script
setup.py install
from a python command prompt (assuming you are on Windows).
But there is no guarantee that this version will work as expected.
As an (easier?) alternative:
If you want to use web.py, try to install python 2.7.x (https://www.python.org/downloads/release/python-2710/) and install web.py via pip afterwards.

python3 in a virtualenv still uses library in /usr/lib/python2.7/dist-packages

I have successfully created a virtual environment with virtualenvwrapper using python3 at /usr/local/bin/python3 as default interpreter. My system python is python2.7
I can't use pip3 in this virtual environment because it keeps looking inside the default /usr/lib/python2.7/dist-packages
(python3.3.3)╭ ➜ xxx#xxx:~VIRTUAL_ENV/bin
╰ ➤ pip3.3
Traceback (most recent call last):
File "/home/xxx/virtualenv/python3.3.3/bin/pip3.3", line 7, in <module>
from pip import main
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 11, in <module>
from pip.basecommand import command_dict, load_command, load_all_commands, command_names
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 11, in <module>
from pip.baseparser import parser, ConfigOptionParser, UpdatingDefaultsHelpFormatter
File "/usr/lib/python2.7/dist-packages/pip/baseparser.py", line 5, in <module>
import pkg_resources
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 45
def _bypass_ensure_directory(name, mode=0777):
^
SyntaxError: invalid token
Am I forgetting something?
I've also tried to install python3 into a custom directory inside /opt but that doesn't help.
Got it. My system $PYTHONPATH contains /usr/lib/python2.7/dist-packages so I simply removed it from the path and everything is now working properly.

Categories

Resources