I have successfully installed gnureadline using both pip (2.x) and pip-3.5. Although importing it in Python2.7 works perfectly, in Python 3.5 it throws the following exception:
Python 3.5.1 (default, Jan 31 2016, 04:03:04)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gnureadline
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gnureadline.so, 2): Symbol not found: _PyInt_AsLong
Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gnureadline.so
Expected in: flat namespace
in /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gnureadline.so
The weird thing is that python looks for the package in the Python2.7 path.
The platform is OSX 10.11.3.
You have to check your PYTHONHOME env variable.
check it with echo $PYTHONHOME, it should point to 3.5 version ,
if it's not true, fix it by the following command
export PYTHONHOME=/full path to appropriate python libs/
After checking the sys.path variable as BasicWolf pointed out, I noticed that the 2.7 site packages were included independent of the python version that I run. This happened due to an override of the PYTHONPATH env variable in my .bashrc file:
export PYTHONPATH=~/Library/Python/2.7/lib/python/site-packages/
Related
I downloaded the source code of python 2.7.14 and built it and installed it on linux ( Red Hat 4.8.5-16 ). I have earlier installed python-magic and requests libraries. Now when I try to import modules installed using pip, I get this:
$ python2
Python 2.7.14 (default, Nov 9 2017, 09:05:45)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import magic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named magic
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
while similar thing works perfectly fine in python 2.7.5 (default with the RHEL system)
$ python
Python 2.7.5 (default, May 3 2017, 07:55:04)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import magic
>>> import requests
>>>
Am I missing any configuration step here?
The modules installed via pip are only available to the standard python version. You need to install your desired packages for the non-standard python versions as well (see also Installing Python Modules)
python2 -m pip install python-magic
python2 -m pip install requests
your pip is default set for version
$ python
Python 2.7.5
SO if you want to install module for
$ python2
Python 2.7.14
use python2 -m pip install module_name
The sys.path must be different for the two installations. That's a list of folders that Python checks for imports.
It's probably simplest to just symlink the one for wherever pip installs to into the modules folder for 2.7.14.
For various reasons, I need to install a python module somewhere outside the default location. pip install --prefix would seem like the right thing, but I'm having problems:
$ pip install --prefix /tmp/foo protobuf-3.2.0-cp27-cp27mu-manylinux1_x86_64.whl
$ export PYTHONPATH=/tmp/foo/lib64/python2.7/site-packages
$ python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import google.protobuf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named google.protobuf
>>> import sys
>>> sys.path.append('/tmp/foo/lib64/python2.7/site-packages')
>>> sys.path
['', '/tmp/foo/lib64/python2.7/site-packages', '/usr/lib64/python27.zip',
'/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2',
'/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old',
'/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages',
'/usr/lib/python2.7/site-packages', '/tmp/foo/lib64/python2.7/site-packages']
>>> import google.protobuf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named google.protobuf
But if I install it in the default location (which I cannot do in production):
$ sudo pip install protobuf-3.2.0-cp27-cp27mu-manylinux1_x86_64.whl
$ python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import google.protobuf
>>> google.protobuf.__version__
'3.2.0'
I assume my invocation of the pip command is wrong, or there is something else I need to do to get at that module at runtime. Any advice would be much appreciated.
The best possible solution for you would be the use of "virtualenv". You can install required packages whose scope will only be limited to the virtual environment. Also it will ignore all the previously installed packages that are already in your main repository. For a quick start, follow this link: http://docs.python-guide.org/en/latest/dev/virtualenvs/
Use:
pip install --ignore-installed --install-option="--prefix=$PREFIX_PATH" package_name
--ignore-installed is to force all dependencies to be reinstalled using this new prefix. This looks to be the problem you're having. You can use --install-option multiple times to add any of the options you can use with python setup.py install with --prefix.
I am not sure why you want this path to be different. You should probably initialize a virtual environment to keep your modules project specific. However, if this is necessary for your use case, do the above.
I just installed Opencv 3.2 using conda forge on Anaconda with python 3.6. While using bash to run import cv2 works alright, running this command on fish shell outputs this error message.
import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/vicarious/anaconda/lib/python3.6/site-packages/cv2.so, 2): Library not loaded: #rpath/libopencv_hdf.3.2.dylib
Referenced from: /Users/vicarious/anaconda/lib/python3.6/site-packages/cv2.so
Reason: image not found
I checked out this question and added set -x DYLD_FALLBACK_LIBRARY_PATH /Users/vicarious/anaconda/lib/ $DYLD_FALLBACK_LIBRARY_PATH fish config file which did not help.
I also disabled MacOS Sierra SIP as it apparently does not let DYLD_FALLBACK_LIBRARY_PATH to be changed. But I still get the same error.
What should I do?
Works for me using fish as my default shell on macOS Sierra 10.12:
python
Python 3.6.0a3 | packaged by conda-forge | (default, Jul 12 2016, 15:51:25)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.__version__)
3.2.0
>>> exit()
If it works in bash but not fish then your bash environment is probably defining an environment var that isn't present in the fish environment or has a different value. Also, I installed opencv2 using conda install -c conda-forge opencv. If you built it from source or installed it in some other manner that is likely a factor.
I have tried dulwich, and GitPython - neither of which seem mature. Now I am trying to install libgit2/pygit2. I have successfully installed them into the host packages environment, but now I need to get them installed in the virtualenv of the app I am building.
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygit2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pygit2/__init__.py", line 32, in <module>
import _pygit2
ImportError: libgit2.so.0: cannot open shared object file: No such file or directory
>>>
As you can see the current issue seems to be that the globally installed libgit2.so.0 cannot be found from within the virtualenv. Fair enough, that is what virtualenv is about after all,, sandboxing. So how do I go about linking/symlinking/building a version/copy of the libgit2.so for the virtualenv ?
I found the following script in a Gist that - when run while logged into a virtualenv -- will install the current libgit2/pygit2 together there in the venv.
https://gist.github.com/olivier-m/5755638
One note of caution, update the version numbers for both libraries to the same most recent version ( 0.20.0 at this time of writing ).
I get the following errors, I've placed [my name] for anonymity:
>>> python /Users/[myname]/Desktop/setuptools-0.6c11/ez_setup.py
File "<stdin>", line 1
python /Users/[myname]/Desktop/setuptools-0.6c11/ez_setup.py
^
SyntaxError: invalid syntax
If you can't see the ^ is under the 11.
Or I get this error:
>>> python /Users/[myname]/Desktop/EZ_tutorial/ez_setup.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined
The ez_setup.py script may or may not work depending on your environment. If not, follow the instructions here. In particular, from the shell, make sure that the python 2.6 you installed is now invoked by the command python:
$ python
Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
If not, modify your shell's PATH environment variable. Then download the setuptools 2.6 python egg from here, change to your brower's download directory, and run the downloaded script:
$ cd ~/Downloads # substitute the appropriate directory name
$ sh setuptools-0.6c11-py2.6.egg
Try running that command from a shell (i.e. straight from Terminal.app), not from inside the python interpreter.