Modules in Python linux

2

I'm having some problems installing modules in my python on linux. I am currently using python 2.7.10, most of the modules I use the pip to install, however when I run python 2.7.10 and import my module it says it has not found, however if I use version 2.7.6 (/ usr / bin / python2.7) they work, it seems that when I install these modules they are only visible to previous version.

Before 2.7.10 I was with 2.7.9 and the same problem happened. Does anyone know what it can be?

    
asked by anonymous 23.06.2015 / 22:06

2 answers

1

You probably have two installations of Python - the 2.7.6 should be the one that came with your Linux distribution, and the 2.7.10, which I imagine you installed by hand, in some corner type /usr/local/ ?

You can use #

/usr/local/bin/python2.7 -m pip

instead of pip whenever you install a package; this will ensure that it will be installed in python 2.7.10, not in python 2.7.6.

    
23.06.2015 / 22:14
0

If your system came with Python 2.7, you can keep it with Python 2.7.10. and your system came with Python 2.6, you can not change the default Python system to 2.7: you're going to destroy your system - most Linux distributions have several key programs for administration that depend heavily on Python on the system.

The correct way to do this is to use the system manager to download the prerequisites for compiling Python (for example, in Debian, Ubuntu and derivatives: "apt-get build-dep python-2.7", in fedora : yum-builddep python2). -Download the source code (the .tar.gz file) from Python.org, and compile a local version for the user - set the prefix to be inside your own Home (./configure --prefix = / home / user / usr) or a separate system prefix of /usr - /opt is a good request. The advantage of using a prefix within your / home is that you do not need super-user ( sudo ) permissions at any time to install the new version of Python.

So, install the virtualenv package in the system Python, and for each project it works on, create a virtualenv, using the Python you have compiled - to do this use the -p of virtualenv argument. Each time you work on the project, activate virtualenv. The sequence, after compiling the new Python, is this:

apt-get install python-virtualenv
virtualenv -p /home/usuario/usr/bin/python-2.7 meuprojeto
cd meuprojeto
source bin/activate

and from there place the .py of your new project inside the folder - and install other modules at will with the command pip : the installed modules will be restricted to virtualenv. A second project that uses different versions of the same modules can be created in another folder, and one project will not interfere with the other.

(The source bin/activate step must be executed on every shell you are running Python programs of this project - there are virtualenv helper packages that allow a simpler command to activate virtualenvs, but the difference is almost cosmetic only)

This recipe works the same way for newer versions of Python - and you can even have separate virtualenvs with Python 3.4 and Python 3.5 beta.

    
24.06.2015 / 07:07