How to install libgit2/pygit2 into virtualenv? (Ubuntu) - python

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 ).

Related

Anaconda does not find any module after Ubuntu upgrade to 18.04

After upgrading my Ubuntu OS from 16.04 LTS to 18.04.4 LTS, my python anaconda distribution does not find any regular module that should be in anaconda (numpy, matplotlib...), for instance, starting python from the command shell:
pjacquot#HP-EliteBook-Folio-1040-G3:python
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:51:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'matplotlib'
>>>
I can not even start spyder:
pjacquot#HP-EliteBook-Folio-1040-G3:~$ spyder
Traceback (most recent call last):
File "/home/pjacquot/anaconda3/bin/spyder", line 7, in <module>
from spyder.app.start import main
ModuleNotFoundError: No module named 'spyder'
I checked that I was using the "good" python:
pjacquot#HP-EliteBook-Folio-1040-G3:which python
/home/pjacquot/anaconda3/bin/python
and that the directory is in my path:
pjacquot#HP-EliteBook-Folio-1040-G3: echo $PATH
/home/pjacquot/anaconda3/bin:/texlive/2017/bin/x86_64-linux
Any idea what's happened there ?
I can still re install all modules, but it's going around the bush as they should be somewhere around here...
The not-clever solution: delete old anaconda (sudo rm -rf anaconda3) and reinstall it from scratch (takes 3 minutes and works...).

pip installed modules and alternate paths

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.

Error while installing package developed with cliff

I wrote a command line tool with cliff 2.3.0, tested on my laptop (Mac, Python 2.7.12). When I was tried to install it (python setup.py install) on a server (Linux, Python 2.7.2), I encountered this error:
Installed /private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-py2.7.egg
ERROR:root:Error parsing
Traceback (most recent call last): File "/private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-> py2.7.egg/pbr/core.py", line 111, in pbr
attrs = util.cfg_to_args(path, dist.script_args) File "/private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-py2.7.egg/pbr/util.py", line 248, in cfg_to_args
kwargs = setup_cfg_to_setup_kwargs(config, script_args) File "/private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-py2.7.egg/pbr/util.py", line 431, in setup_cfg_to_setup_kwargs
if pkg_resources.evaluate_marker('(%s)' % env_marker):
AttributeError: 'module' object has no attribute 'evaluate_marker' error: Setup script exited with error in setup command: Error parsing /private/tmp/easy_install-EGMO15/cliff-2.3.0/setup.cfg: AttributeError: 'module' object has no attribute 'evaluate_marker'
Any suggestions?
It looks like your server may have a (much) older version of the setuptools package installed (which provides the pkg_resources module). The evaluate_marker method looks as if it first showed up at the end of 2014, so if you're using an older system it is possible that method is not available.
Depending on your environment, you may be able to simply pip install -U setuptools, or you may need to see if your distribution has a newer isntallable package available.
If you can update your question to include details about your server's operating environment (what distribution and version are you running? What version of Python? What version of setuptools?), we can probably provide a more complete answer.
Update
For example, Ubuntu 12.04 only has setuptools 0.6, and the pkg_resources module (which is packaged in the python-pkg-resources package) does not have the evaluate_marker method:
# python
Python 2.7.3 (default, Jun 22 2015, 19:33:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> pkg_resources.evaluate_marker
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'evaluate_marker'
In this environment, I can install pip:
# apt-get install python-pip
And then upgrade the installed version of setuptools:
# pip install -U setuptools
And now:
# python
Python 2.7.3 (default, Jun 22 2015, 19:33:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> pkg_resources.evaluate_marker
<function evaluate_marker at 0x1535050>
>>>
NB Upgrading distribution packages (e.g., things installed by apt-get in this example) using pip can often lead to sadness and heartache, and you are much better off if you are able to upgrade the underlying environment to one where such workarounds are not necessary. Alternatively, running your code from a Python virtual environment (so that your upgraded packages do not override system packages) is also a technically better solution.

Importing third-party modules within a virtualenv

Following the trouble I described here trying to install an older wPython inside a virtualenv, I then downloaded the dmg directly in a browser, and (after needing to right-click on the .pkg), it successfully got installed.
When I open an intepreter, I confirm that I can import wx.
Yet when I recreate my virtualenv, activate it, and open its intepreter:
(venv)MacBook-Pro-de-Pyderman:Projet Pyderman$ python
Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named wx
Is there a step I am missing with respect to being able to import third-party modules within a virtualenv?
You should try creating the virtualenv with the --system-site-packages option. This will allow you to access the packages installed at system level, like the ones you install from a dmg image.

Mac OS 10.9's (Mavericks) deinstalled Django

After installing Mac OS 10.9 (Mavericks) the Django version is no longer installed or apparently the system can't find the right paths to make it runs. How can I repair this?
This are the errors I'm getting trying to run Django:
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
>>>
$ python manage.py
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
Did you install Django into your main Python directory? If so, the version of Python might have been upgraded. This might have wiped your central site-packages. If, so, just reinstall Django.
Alternatively, and more advisable, use virtualenv. This will create a separate Python environment (including site-packages for each project), preventing this (probably) from happening again in future.
Install VirtualEnv Systemwide then setup virtual env
Installing
sudo easy_install virtualenv
now create project folder and cd into that after that
virtualenv venv
. venv/bin/activate
then install django using pip
pip install django

Categories