Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

numpy - Possible conflicting python installations

I'm not sure if the default python installation is the one that I've been installing modules to, and if that may be the cause of a conflicting Unicode byte size compatibility error. In short, I've installed Numpy 1.7 using Python 2.7.3 and when I try to install this other program that uses Python and Numpy as dependencies, I get this error:

Traceback (most recent call last):
  File "setup.py", line 20, in <module>
    from weblogolib import __version__
  File "/home/chris/Documents/IS/Bioinformatics-Software/weblogo-3.3/weblogolib/__init__.py", line 108, in <module>
    from numpy import array, asarray, float64, ones, zeros, int32,all,any, shape
  File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
  File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
  File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
  File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
  File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: /usr/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS4_AsUnicodeEscapeString

So I guess I have a conflicting unicode byte size (2-byte vs. 4-byte). I went to check to see if I had conflicting versions of Python that could be messing this up.

python --version
Python 2.7.3

But this seems at odds with

which python
/usr/local/bin/python

When I go to /usr/local/bin I find these files (relevant to python):

python
python2
python2.7
python-config
python2-config
python2.7-config

Now I've installed numpy into the dist-packages directory of /usr/lib/python2.7/dist-packages which corresponds to what I get for python --version. But the fact that when I try which python and get a directory for python and not python2.7 concerns me that this might be conflicting when I try to install the program that uses python and numpy as dependencies.

So I guess to clarify my question(s): Are these normal files to find for a python installation or have I somehow installed three different versions? Could they be causing my error with the unrecognized symbol? Is there a way to uninstall if they are indeed extraneous versions?

Thanks for any help you can provide!

Oh and here is a link to a previous question I had, where I edited the PYTHONPATH while trying to fix an ImportError I was getting, if that might be affecting things....ImportError: No module named numpy

Here are the results of trying virtualenv:

chris@ubuntu:~/Documents/IS/Bioinformatics-Software$ virtualenv weblogo-3.3
New python executable in weblogo-3.3/bin/python
Installing setuptools.............done.
Installing pip...............done.
chris@ubuntu:~/Documents/IS/Bioinformatics-Software$ cd weblogo-3.3
chris@ubuntu:~/Documents/IS/Bioinformatics-Software/weblogo-3.3$ source bin/activate
(weblogo-3.3)chris@ubuntu:~/Documents/IS/Bioinformatics-Software/weblogo-3.3$ pip install numpy
Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/lib/python2.7/dist-packages
Cleaning up...
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The problem indeed seems to be a mismatch of Python and Numpy compile settings.

/usr/local/bin is where custom Python is installed, you should try to run using /usr/bin/python instead.

Another solution is to use a virtualenv. Try this:

virtualenv myproject
cd myproject
source bin/activate
pip install numpy

Basically virtualenv sets up a different Python installation with its own packages in the "myproject" directory. Running the "activate" command tells the system that you want to use this installation instead of the default system. This lets you have a different Python environment for different projects. Using virtualenv, each project can have its own versions of Python packages even if they're incompatible with other projects or system packages.

Note you will have to repeat the "source" command each time you open a new shell and want to use that virtual environment. Also you might have to install the virtualenv command by using your OS package manager. If this isn't possible (e.g. you don't have root access) or your OS version is too old for some reason, you can also download it manually from https://pypi.python.org/packages/source/v/virtualenv/

If you do ls -l /usr/local/bin/python* you should see that python and python2 are actually symlinks to python2.7, and likewise python-config and python2-config are symlinks to python2.7-config.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...