I tried to smoothly pass from python 2.7 to python 3.X (3.5.2). This is a two-step question so I tried to make it clear.
1. I made a simple trial with
import numpy as np
(I did a python3 -m pip install numpy
first) But I received the following error message
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray'
Is the erorr somehow connected with python2.7 ?
2. When I tried to import modules I already installed ( pip install module
) python3 do not find them ( ImportError: No module named ...
). In this second case I think that the directory in which I install the modules is connected with python 2.7. How can I point python3 to modules I already have? My dream is to avoid using python3 -m pip install ModuleName
, I would like to not reinstall each single modules by hands (I also do not remember which I have and why :) ).
I am using Ubuntu 16.04.1 LTS. In my .bashrc
I have the following segment, maybe is not important, but I try to give more informations as possible
# added by me for the python import module installed outside anaconda2 (i.e.: pygtk)
export PYTHONPATH="${PYTHONPATH}:/usr/lib/python2.7/dist-packages/"
export PYTHONPATH="${PYTHONPATH}:/usr/lib/python2.7/dist-packages/glib/"
Many thanks.
You should definitely not have those lines in your .bashrc. Remove them and start a new shell.
And no, you need to reinstall the modules you need for Python3.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.