Pyinstaller freezes an invalid binary when includes ZMQ - python-2.7

I'm trying to freeze a binary with PyInstaller that includes ZMQ code. When testing the application everything works fine with Python interpreter, but final binary does not work at all.
Note: A different code is used here to illustrate and simplify the error:
try:
import zmq
zmq.Context()
except Exception, e:
print str(e)
print 'end'
Python version is 2.7.6, Operating System is CentOS 6.7 and I'm working with a virtual environment which includes the following packages:
(Compiler)[user#machine test]$ pip list
backports.ssl-match-hostname (3.4.0.2)
certifi (2015.9.6.2)
cffi (1.2.1)
cryptography (1.0.1)
Cython (0.23.1)
distribute (0.7.3)
enum34 (1.0.4)
futures (3.0.3)
idna (2.0)
ipaddress (1.0.14)
Jinja2 (2.8)
M2Crypto (0.22.3)
MarkupSafe (0.23)
msgpack-python (0.4.6)
npyscreen (4.10.0)
pip (7.1.2)
psutil (3.2.1)
pyasn1 (0.1.8)
pycparser (2.14)
pycrypto (2.6.1)
PyInstaller (2.1)
pyroute2 (0.3.14)
python-iptables (0.9.0)
pytz (2015.4)
PyYAML (3.11)
pyzmq (14.7.0)
requests (2.7.0)
salt (2015.5.5)
setuptools (18.0.1)
six (1.9.0)
tornado (4.2.1)
tzlocal (1.2)
wheel (0.24.0)
And this other rpm package has been installed through YUM tool:
[root#machine test]# rpm -qa | grep -i zmq
python-zmq-14.3.1-1.el6.x86_64
Case ONE: Works with Python Interpreter.
(Compiler)[user#machine test]$ python test.py
end
Case TWO: Does NOT work after PyInstaller.
(Compiler)[user#machine test]$ pyinstaller --onefile test.py
...
12135 INFO: building EXE from out00-EXE.toc
12136 INFO: Appending archive to EXE /test/dist/tes
(Compiler)[user#machine test]$ /test/dist/test
/tmp/_MEIl3jKVa/zmq/libzmq.so: undefined symbol: crypto_secretbox_open
end
What I'm missing? Thanks in advance!

Problem seems to be fixed by downgrading pyzmq version from 14.X to 13.X (eg: 13.1.0 has been tested successfully).
I think pyzmq includes pyNacl (libsodium) libraries on 14.X and onwards. However, I have also tried to freeze with Pyinstaller after installing pyNacl (0.3.0) in my virtual environment and I got the same error.
Does anyone knows how to do this with latest version of pyzmq?

Related

Python click project, "Django is not available on the PYTHONPATH " error

I am having a click project which don't use/need Django anywhere but while running prospector as part of static analysis throws this strange error
Command
prospector -I __init__.py --strictness veryhigh --max-line-length 120 src/
Error
Line: 1
pylint: django-not-available / Django is not available on the PYTHONPATH
There was no reference of django anywhere in the project/code . I am fairly new to python, Am i missing something obivious here ?
python-version : 3.7
pip list
apipkg 1.5
asn1crypto 1.2.0
astroid 2.3.2
atomicwrites 1.3.0
attrs 19.3.0
auger-python 0.1.35
bitmath 1.3.3.1
boto3 1.10.14
botocore 1.13.14
bravado 9.2.0
bravado-core 4.9.1
certifi 2019.9.11
cffi 1.13.2
chardet 3.0.4
click 6.7
colorama 0.4.1
coloredlogs 10.0
coverage 4.5.4
cryptography 2.3.1
deb-pkg-tools 4.5
docutils 0.15.2
dodgy 0.1.9
entrypoints 0.3
execnet 1.7.1
executor 21.3
fasteners 0.15
filelock 3.0.12
flake8 3.7.9
flake8-polyfill 1.0.2
funcsigs 1.0.2
future 0.18.2
humanfriendly 4.18
hvac 0.7.1
idna 2.5
importlib-metadata 0.23
isort 4.3.21
jmespath 0.9.4
jsonpointer 2.0
jsonschema 3.1.1
lazy-object-proxy 1.4.3
mando 0.6.4
mccabe 0.6.1
mock 3.0.5
monotonic 1.5
more-itertools 7.2.0
murl 0.5.1
packaging 19.2
pep8 1.7.1
pep8-naming 0.4.1
pip 19.3.1
pluggy 0.13.0
property-manager 2.3.1
prospector 1.1.7
py 1.8.0
pycodestyle 2.5.0
pycparser 2.19
pydocstyle 4.0.1
pyflakes 2.1.1
pylint 2.4.3
pylint-celery 0.3
pylint-django 2.0.10
pylint-flask 0.6
pylint-plugin-utils 0.6
pyparsing 2.4.4
pyrsistent 0.15.5
pytest 5.2.2
pytest-cache 1.0
pytest-cov 2.8.1
pytest-pep8 1.0.6
python-dateutil 2.6.1
python-debian 0.1.33
python-memcached 1.59
pytz 2019.3
PyYAML 5.1.2
radon 4.0.0
raven 6.9.0
requests 2.19.1
requirements-detector 0.6
rfc3987 1.3.8
customcli 0.1.dev27+g2b07461.d20191114
s3transfer 0.2.1
setoptconf 0.2.0
setuptools 41.6.0
simplejson 3.16.0
six 1.12.0
snowballstemmer 2.0.0
strict-rfc3339 0.7
swagger-spec-validator 2.4.3
toml 0.10.0
tox 3.14.0
tryagain 1.0
typed-ast 1.4.0
urllib3 1.23
verboselogs 1.7
virtualenv 16.7.7
wcwidth 0.1.7
webcolors 1.10
wheel 0.33.6
wrapt 1.11.2
zipp 0.6.0
As I said in my comments I think there is a bug with prospector and requirement-detector.
I was able to reproduce the problem by just installing prospector 1.1.7 in an empty virtualenv:
$ pip freeze
astroid==2.2.5
dodgy==0.1.9
isort==4.3.21
lazy-object-proxy==1.4.3
mccabe==0.6.1
pep8-naming==0.4.1
prospector==1.1.7
pycodestyle==2.3.1
pydocstyle==4.0.1
pyflakes==1.6.0
pylint==2.3.1
pylint-celery==0.3
pylint-django==2.0.10
pylint-flask==0.6
pylint-plugin-utils==0.6
PyYAML==5.1.2
requirements-detector==0.6
setoptconf==0.2.0
six==1.13.0
snowballstemmer==2.0.0
typed-ast==1.4.0
wrapt==1.11.2
Then creating a dummy code:
$ cat src/__init__.py
print('something')
When running prospector I got the same error:
$ prospector src/
/home/sma/.pyenv/versions/3.7.3/envs/58918408_so/lib/python3.7/site-packages/pycodestyle.py:113: FutureWarning: Possible nested set at position 1
EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
Messages
========
src/__init__.py
Line: 1
pylint: django-not-available / Django is not available on the PYTHONPATH
Check Information
=================
Started: 2019-11-18 17:57:27.136877
Finished: 2019-11-18 17:57:27.301151
Time Taken: 0.16 seconds
Formatter: grouped
Profiles: default, no_doc_warnings, no_test_warnings, strictness_medium, strictness_high, strictness_veryhigh, no_member_warnings
Strictness: None
Libraries Used: django, flask, celery
Tools Run: dodgy, mccabe, pep8, profile-validator, pyflakes, pylint
Messages Found: 1
Since prospector issue 245 and pylint django PR 137 Django became an extra dependency of pylint-django.
But running it without django installed still return a message:
$ pylint --load-plugins pylint_django src
************* Module src
src/__init__.py:1:0: C0111: Missing module docstring (missing-docstring)
src/__init__.py:1:0: F5101: Django is not available on the PYTHONPATH (django-not-available)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
My guess is prospector catch that message and return it when ran directly i.e with dependency automatic detection.
This seems like an bug/integration problem between the two libraries for me, but a confirmation from a contributor/maintainer from one the project is required.
Otherwise #Thaveedu a workaround is to disable the dependency automatic detection since in your case you probably don't care about django, flask or celery anyway:
$ prospector --no-autodetect src/
/home/sma/.pyenv/versions/3.7.3/envs/58918408_so/lib/python3.7/site-packages/pycodestyle.py:113: FutureWarning: Possible nested set at position 1
EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
Check Information
=================
Started: 2019-11-18 18:07:30.662236
Finished: 2019-11-18 18:07:30.804708
Time Taken: 0.14 seconds
Formatter: grouped
Profiles: default, no_doc_warnings, no_test_warnings, strictness_medium, strictness_high, strictness_veryhigh, no_member_warnings
Strictness: None
Libraries Used:
Tools Run: dodgy, mccabe, pep8, profile-validator, pyflakes, pylint
Messages Found: 0
After some investigation, Propector supports Django, Celery and Flask, which means it automatically installs the Pylint plugins needed for it to support these frameworks.
Is it possible you have specified to use pylint-django? In order for pylint-django to inspect Django code it requires Django to be installed, prospector docs states it doesn't normally automatically detect your project's dependencies, but it states you can turn them off using:
prospector --no-autodetect
Let me know if this helps.

python - pip installs but cannot import

I've read a lot of posts about this but none of the solutions have worked for me. I'm trying to get a module called nsxramlclient installed, shows successful installation with pip but cannot import from any location outside of the /Users/Nathan/Library/Python/2.7/lib/python/site-packages.
Uninstall does work after some fidgeting with brew using the recommendations found with brew doctor. Here are some vitals:
Running OSX python 2.7.10
PIP 18.1
which -a pip = /usr/local/bin/pip
which -a python = shows 2 directories:
/usr/local/bin/python
/usr/bin/python
python -c 'import sys; print(sys.path)'
['', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload']
pip list | grep nsxramlclient
nsxramlclient 2.0.7
It has to be a path issue since I'm able to import it from the directory that the module is located. I just don't know the proper method to repair this since I'm fairly new to Python and I don't want to mess it up worse that it is already.
Looks like I did end up getting it to work finally. What I had to do was to re-install python with brew:
brew re-install python#2
then I needed to re-install the modules I needed with pip. Having OTHER issues now but at least this one is fixed.

nltk module installation in pip through cmd

When I tried to run this command:
c:\python27\scripts\pip install nltk-3.2.1-py2.py3-none-any
I am getting the error:
no matching distribution found
Although i have installed nltk from
http://www.lfd.uci.edu/~gohlke/pythonlibs/#nltk
Kindly help.
I am working on Windows 8 64-bit Version
Installing new modules can be a nightmare if you are new to Python.First delete any old versions of NLTK if already installed. Open cmd navigate to C:\Users\user\AppData\Local\Programs\Python\Python35-32\Scripts, the default directory, using the command cd path_name_comes_here. Otherwise goto the path where you have installed python and goto the Scripts subfolder and use this path here onwards. Now the most preferred way is to use pip install module_you_want_to_install for anything in python. Pip automatically fetches everything it needs to install said module.
Simply use pip install nltk.
Another method is to use easy_install requirement_or_URL.
Some rare occasions its best to download the wheel from http://www.lfd.uci.edu/~gohlke/pythonlibs and from there you can simply use pip install downloaded_wheel_name again. But make sure to copy the name of the wheel EXACTLY.
Post installation make sure that your package is accessible from C:\Users\user\AppData\Local\Programs\Python\Python35-32\Lib\site-packages or a similar path depending on where you installed python.
Try Anaconda - Instead . Always works
C:\Users\sanan>conda install -c anaconda nltk
Fetching package metadata .............
Solving package specifications: .
Package plan for installation in environment C:\Users\sanan\Miniconda3:
The following NEW packages will be INSTALLED:
nltk: 3.2.4-py36_0 anaconda
The following packages will be UPDATED:
conda: 4.3.23-py36_0 --> 4.3.25-py36_0 anaconda
The following packages will be SUPERSEDED by a higher-priority channel:
conda-env: 2.6.0-0 --> 2.6.0-0 anaconda
Proceed ([y]/n)? y
conda-env-2.6. 100% |###############################| Time: 0:00:00 22.84 kB/s
nltk-3.2.4-py3 100% |###############################| Time: 0:00:02 774.24 kB/s
conda-4.3.25-p 100% |###############################| Time: 0:00:00 578.90 kB/s
After installation is complete .
import nltk
print(nltk.__version__)
C:\Public\Code\textnorm>python attempt1.py
3.2.4

"ImportError: ... Expected in: flat namespace" when setting up a mysql database

mySQL seems to be up and running just fine. But when I try to import MySQLdb into python I get a ImportError: ... Expected in: flat namespace. I think it has to do with having two different versions for python (well two different directories, same version)
OS: Mac 10.6.8
$ ls /Library/Frameworks/Python.framework/Versions/
7.2 Current
$ which python
/Library/Frameworks/Python.framework/Versions/Current/bin/python
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/Current/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin
$ easy_install MySQL-python
...
...
Using /Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-i386.egg
...
$ mysql.server start
Starting MySQL
.. SUCCESS!
$ python manage.py runserver
...
...
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-i386.egg/_mysql.so, 2): Symbol not found: _mysql_affected_rows
Referenced from: /Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-i386.egg/_mysql.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-i386.egg/_mysql.so
$ python
Enthought Python Distribution (EPD) free version -- www.enthought.com
Version: 7.2-2 (32-bit)
>>> import MySQLdb
...
...
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-i386.egg/_mysql.so, 2): Symbol not found: _mysql_affected_rows
Referenced from: /Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-i386.egg/_mysql.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-i386.egg/_mysql.so
So in addition to being new to django and python I'm also new to using the terminal, and I'm not exactly sure what I'm looking at.
But I can tell the obvious:
I have two versions, 7.2 and current.
If I call python it will call the 'Current' version. That makes sense, it's in $PATH.
However, a version 2.7 (not 7.2) is also in PATH which I had deleted when I installed the EDP package. ...I don't fully understand what PATH is or does so I didn't want to start changing things
MySQL-python is installed in version 7.2
Can't run the server because a necessary file isn't in flat namespace and it's at the place it was installed too
Is there some way to untangle these paths (if that's the problem)
thank you in advance
Well... I don't think it had anything the do with the "Current" and "7.2" versions of python.
It seems to have fixed itself after doing
pip uninstall MySQL-python
brew uninstall mysql
brew install mysql --universal
pip install MySQL-python
I'm not sure if the --universal made the diference or using pip install as opposed to easy_install

pip can't find latest versions of a pypi project

I'm trying to install http://pypi.python.org/pypi/django-crowdsourcing/1.1.21 using pip. I'm getting
$ pip install django-crowdsourcing==1.1.21
Downloading/unpacking django-crowdsourcing==1.1.21
Could not find a version that satisfies the requirement django-crowdsourcing==1.1.21 (from versions: )
No distributions matching the version for django-crowdsourcing==1.1.21
If I try an upgrade, it only finds version 1.1.19.
$ pip install -v --upgrade django-crowdsourcing
Downloading/unpacking django-crowdsourcing
Using version 1.1.19 (newest of versions: 1.1.19, 1.1.18, 1.1.17, 1.1.16, 1.1.15, 1.1.14, 1.1.13, 1.1.12, 1.1.11, 1.1.10, 1.1.9, 1.1.8, 1.1.7, 1.1.6)
Downloading django-crowdsourcing-1.1.19.tar.gz (651Kb): 651Kb downloaded
...
Successfully installed django-crowdsourcing
It looks like django-crowdsourcing version 1.1.21 has some good tags
$ hg tags
tip 289:8796aae85e34
1.1.21 288:2f39596495a7
1.1.20 281:fe00699aa3ff
1.1.19 278:17392ea8ea54
and the correct version number in setup.py
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
import os
readme_file = os.path.join(os.path.dirname(__file__),
'README')
long_description = open(readme_file).read()
classifiers = [
'Development Status :: 4 - Beta',
'Framework :: Django',
'License :: OSI Approved :: MIT License']
setup(name='django-crowdsourcing',
version='1.1.21',
classifiers=classifiers,
description='Django app for collecting and displaying surveys.',
long_description=long_description,
author='Jacob Smullyan, Dave Smith',
author_email='jsmullyan#gmail.com',
url='http://code.google.com/p/django-crowdsourcing/',
packages=['crowdsourcing', 'crowdsourcing.templatetags'],
license='MIT',
)
PyPi clearly knows about version 1.1.21 since that's what comes up when you go to http://pypi.python.org/pypi/django-crowdsourcing/ Why does pip think version 1.1.19 is the latest version?
Edit
Sheepishly, I forgot to point out I'm the maintainer. #Matthew Schinckel is right. Here are the two commands I needed, which I found out from a tutorial I didn't see before: http://wiki.python.org/moin/Distutils/Tutorial
$ python setup.py register
$ python setup.py sdist upload
There is no packaged file at version 1.1.21. There is one at 1.1.19. Tags in hg mean nothing to pip: it will only download a packaged up file.
Perhaps contact the maintainer, and point out there is no file release with the two most recent versions on pypi.