I'm learning python and I'm using OS X. I've installed anaconda 3 and set up env called testenv with python 3.5. Then I activated recently created env and installed several packages such as numpy, pandas and opencv3. Nevertheless, when I run python shell and type "import numpy" I get the following errors:
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): Symbol not found: _PyBuffer_Type
Referenced from: /usr/local/lib/python2.7/site-packages/numpy/core/multiarray.so
Expected in: flat namespace
in /usr/local/lib/python2.7/site-packages/numpy/core/multiarray.so
The same happens with other packages.
File "/usr/local/lib/python2.7/site-packages/numpy/init.py", line
180, in
Python is picking up the packages from the system's Python packages and not from the packages installed in your virtualenv i.e. testenv.
Be sure that you have activated the virtualenv with something like:
source testenv/bin/activate
and then try running Python.
And you said you set it up with Python 3.5 but it's picking path with python2.7.
Let me know if that solves your problem.
I solved this problem by simply writing this command:
sudo python3 -m pip install --upgrade numpy
Another possible method to fix it is to eliminate /usr/local/lib/python2.7 in PYTHONPATH
On a Mac.... this is how to do this safely
brew install python3
Lets now add a virtual env called pe35
python3 -m venv ~/pe35
Now lets use the virtualenv
source ~/pe35/bin/activate
If you want a symbol - place this in you .bash_profile
alias pe35='source ~/pe35/bin/activate'
Now to install numpy in your virtualenv
pip install numpy
Related
I am trying to run a script importing numpy, and it shows this error:
Traceback (most recent call last):
File "C:/Users/<user>/pycharm/<my_project>/../examples/<my_file>.py", line 5, in <module>
import numpy as np
File "C:\Users\<user>\pycharm\<myproject>\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Users\<user>\pycharm\<myproject>\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "C:\Users\<user>\pycharm\<myproject>\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
from . import overrides
File "C:\Users\<user>\pycharm\<myproject>\lib\site-packages\numpy\core\overrides.py", line 47, in <module>
""")
RuntimeError: implement_array_function method already has a docstring
Process finished with exit code 1
I googeled and my results are
that it might have to do with importing numpy multiple times and
that it might be related to some software called usgwi that python may run under.
I am using python 3.7 and numpy 1.18.5.
Thank you!
I think issue with numpy.
See https://github.com/numpy/numpy/issues/14384
I had issue in VSCode using python AREPEL. I fixed with:
python3 -m pip install --user numpy -U
$ python3 -m pip freeze | grep numpy
numpy==1.19.4
$ python3 --version
Python 3.8.6
Downgrading numpy to numpy==1.15.4 will solve this issue.
pip install --no-cache-dir -I numpy==1.15.4
I have virtual environment created for python 3.6. And I have install python3-pyqt5.qtwebkit package with apt-get. The package have installed in global python3.5 and its working, but if I try to import it from venv python3.6 there is import error... How can I install this package in my virtual environment? Or if this is not possible how can I use global package installed in 3.5 in my virtualenv 3.6 python.
Running with global python3.5
(virtualenv)
~/vcs-ss/sst master ✗ 5d ▴ ⚑ ✚ ◒
▶ python3.5 -c 'import PyQt5.QtWebKit; print(PyQt5.QtWebKit.__file__)'
/usr/lib/python3/dist-packages/PyQt5/QtWebKit.cpython-35m-x86_64-linux-gnu.so
Running with python3.6 from venv
(virtualenv)
~/vcs-ss/sst master ✗ 5d ▴ ⚑ ✚ ◒
▶ python3.6 test/e2e/browser.py
Traceback (most recent call last):
File "test/e2e/browser.py", line 8, in <module>
from PyQt5.QtWebKit import *
ModuleNotFoundError: No module named 'PyQt5.QtWebKit'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "test/e2e/browser.py", line 8, in <module>
from PyQt5.QtWebKit import *
ModuleNotFoundError: No module named 'PyQt5.QtWebKit'
In order to use system packages inside a virtual environment, you have to use --system-site-packages option when creating virtual env:
virtualenv --python=python3.6 --system-site-packages env
The same switch is available in Python3's venv.
Much better option is (if applicable in your case) to install all packages inside your virtual env, using pip.
If you look at the contents of the package (using dpkg --listfiles python3-pyqt5.qtwebkit) you'll probably see something like this:
/.
/usr
/usr/lib
/usr/lib/python3
/usr/lib/python3/dist-packages
/usr/lib/python3/dist-packages/PyQt5
/usr/lib/python3/dist-packages/PyQt5/QtWebKit.cpython-35m-x86_64-linux-gnu.so
/usr/lib/python3/dist-packages/PyQt5/QtWebKit.pyi
/usr/lib/python3/dist-packages/PyQt5/QtWebKitWidgets.cpython-35m-x86_64-linux-gnu.so
/usr/lib/python3/dist-packages/PyQt5/QtWebKitWidgets.pyi
/usr/share
/usr/share/doc
/usr/share/doc/python3-pyqt5.qtwebkit
/usr/share/doc/python3-pyqt5.qtwebkit/copyright
/usr/share/doc/python3-pyqt5.qtwebkit/changelog.Debian.gz
The package installs binary modules compiled for a specific python version (in this case: cpython-35m), you won't be able to use those from a python3.6 installation/venv directly because of the incompatible binary names.
For that to work you'd need to symlink all the .so files in the PyQt5 directory to your venv and there change cpython-35m-x86_64-linux-gnu to cpython-36m-x86_64-linux-gnu. Same for the sip libraries, as those are requiered by PyQt5. And that will only work if the ABI is compatible between the two versions.
A quick test with the versions mentioned above shows it works at least for simple scripts, but I can't give any guarantee.
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.
I am on OS X 10.11.2, Anaconda Python 2.7.10.
I was installing some dependencies, and suddenly, my conda command started not working at all. Many people suggest conda install python=2.7.10 but when I try that (or any command, even just conda) I get:
Traceback (most recent call last): File
"/Users/Can/anaconda/bin/conda", line 5, in
sys.exit(main()) File "/Users/Can/anaconda/lib/python2.7/site-packages/conda/cli/main.py",
line 106, in main
from conda.cli import conda_argparse File "/Users/Can/anaconda/lib/python2.7/site-packages/conda/cli/conda_argparse.py",
line 16, in
from conda.cli.find_commands import find_commands, find_executable File
"/Users/Can/anaconda/lib/python2.7/site-packages/conda/cli/find_commands.py",
line 9, in
from conda.utils import memoized File "/Users/Can/anaconda/lib/python2.7/site-packages/conda/utils.py", line
10, in
import tempfile File "/Users/Can/anaconda/lib/python2.7/tempfile.py", line 32, in
import io as _io File "/Users/Can/anaconda/lib/python2.7/io.py", line 51, in
import _io ImportError: dlopen(/Users/Can/anaconda/lib/python2.7/lib-dynload/_io.so, 2):
Symbol not found: __PyCodecInfo_GetIncrementalDecoder Referenced
from: /Users/Can/anaconda/lib/python2.7/lib-dynload/_io.so Expected
in: dynamic lookup
How can I repair conda, without using conda itself (as I can't)?
UPDATE: I've completely uninstalled and reinstalled Anaconda. It still gives the same error. I've tried pip and it also fails with the same error. I verify it's Anaconda's pip as which pip returns /Users/Can/anaconda2/bin/pip. Why is Anaconda broken?
I had the same issue, it is successfully fixed by just replacing the _io.so file.
sudo find / -name _io.so
copy the path of the _io.so file which DOES NOT belong to python-2.7.11. For example, copy the path of _io.so which is under python-2.7.5:
/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Replace the '/Users/Can/anaconda/lib/python2.7/lib-dynload/_io.so' file with the _io.so that you just found.
cp /usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so /Users/Can/anaconda/lib/python2.7/lib-dynload/
Then it will work.
I installed anaconda, but I'm also using pip:
$ conda list scipy
# packages in environment at /Users/bjelline/anaconda:
#
scipy 0.14.0 np19py27_0
$ conda list pybrain
# packages in environment at /Users/bjelline/anaconda:
#
pybrain 0.3 <pip>
These two are supposed to work together, aren't they?
when I do
/Users/bjelline/anaconda/bin/python -c "import pybrain"
I get an error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/bjelline/anaconda/lib/python2.7/site-packages/pybrain/__init__.py", line 1, in <module>
from structure.__init__ import *
File "/Users/bjelline/anaconda/lib/python2.7/site-packages/pybrain/structure/__init__.py", line 1, in <module>
from connections.__init__ import *
File "/Users/bjelline/anaconda/lib/python2.7/site-packages/pybrain/structure/connections/__init__.py", line 1, in <module>
from full import FullConnection
File "/Users/bjelline/anaconda/lib/python2.7/site-packages/pybrain/structure/connections/full.py", line 3, in <module>
from scipy import reshape, dot, outer
ImportError: cannot import name reshape
any thoughts what the problem might be?
the problem wasn't anaconda, or python, or pip. The problem were files called
pybrain.py
and
scipy.py
in the current directory. the current directory is first in sys.path, so these files got loaded instead of the real libraries.
Note to self: never reuse a packages name as your own filename!
Try conda install -f scipy. This will force reinstall scipy.