I have an OpenShift gear with a python3.3 cartridge. On this, I am attempting to install Scipy. I have tried the simplest method of simply putting scipy in the install_requires field of the setup.py file.
This did not work, I get the error:
ImportError: No module named 'numpy.f2py'
Okay so perhaps I need to upgrade my version of numpy. I try the obvious again of changing numpy to numpy==1.8.2 in the install_requires field of the setup command. This appears to install fine, but I get the same error from the installation of scipy.
Okay, so now I try ssh-ing into my openshift gear (rhc ssh app-name). I try the first thing to simply pip install scipy, and I basically get the same error:
$ source ~/python/virtenv/venv/bin/activate
(venv) $ pip install scipy
...
ImportError: No module named 'numpy.f2py'
Cleaning up ...
...
Okay so I try a pip freeze:
(venv) $ pip freeze
...
numpy=1.7.2
...
Similarly:
(venv) $ python
Python 3.3.2 (default, Mar 20 2014, 20:25:51)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy.f2py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'numpy.f2py'
Okay so let's try forcing the upgrade:
(venv) $ pip install --upgrade -I numpy
.... success ....
(venv) $ pip freeze
...
numpy=1.7.2
Hmm. I try it with and without the -I and with and without numpy==1.8.2. Each with the same result. Numpy really wants to stay at the globally installed version. Now if I look into the lib directory I see:
(venv) $ ls ~/python/virtenv/venv/lib/python3.3/site-packages
bottle-0.12.7-py3.3.egg pip-1.5.6.dist-info
docopt-0.6.2-py3.3.egg __pycache__
easy-install.pth pyparsing-2.0.2-py3.3.egg
Jinja2-2.7.3-py3.3.egg SQLAlchemy-0.9.7-py3.3-linux-x86_64.egg
lazy-1.2-py3.3.egg virtualenv-1.11.6.dist-info
...
Okay so basically every package I have in my install_requires field of the setup.py other than numpy. So now I look in the lib64 directory:
(venv) $ ls ~/python/virtenv/venv/lib64/python3.3/site-packages
numpy numpy-1.8.0-py3.3.egg-info numpy-1.8.1-py3.3.egg-info numpy-1.8.2-py3.3.egg-info
So basically every upgraded version of numpy I have attempted to install (which have reported success). So, how do I get pip freeze to see into this directory? I guess more generally I need the pip echo-system and python to see the installed packages in this directory.
Or alternatively, what am I doing wrong?
Related
Here is a sequence of my commands, and my system's response. This shows that I do not know how to access numpy with my current (very confusing) Python setup. It was recently working, but then I changed something, but can't remember what.
I run MacOs 10.14.6 on a Macbook Pro.
dbae$ which $SHELL
/bin/bash
dbae$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Copyright (C) 2007 Free Software Foundation, Inc.
dbae$ echo $PATH
/Users/dbae/bin:/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/bin:/usr/local/texlive/2018/bin/universal-darwin:/usr/local/texlive/2018/bin/x86_64-darwin:/Library/TeX/texbin:/opt/X11/bin:/Users/dbae/Library/Python/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:
dbae$ python run.py
Traceback (most recent call last):
File "run.py", line 9, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'
dbae$ which python
/opt/local/bin/python
dbae$ /opt/local/bin/python --version
Python 3.8.3
dbae$ which pip
/opt/local/bin/pip
dbae$ /opt/local/bin/pip --version
pip 19.3.1 from /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip (python 3.6)
dbae$ pip install --upgrade pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/43/84/23ed6a1796480a6f1a2d38f2802901d078266bda38388954d01d3f2e821d/pip-20.1.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 19.3.1
Uninstalling pip-19.3.1:
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/pip'
Consider using the `--user` option or check the permissions.
dbae$ pip install numpy
Requirement already satisfied: numpy in /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (1.17.4)
Actually, you kind of screwed your pip setup. Start with the beginning :
$ python -m pip list
What is returned by this command ?
I would suggest you start using virtual environment (venv). It is much easier to handle module dependency issues in the future.
$ python -m venv /path/to/env
$ source /path/to/env/bin/activate # Activates your environment
$ python -m pip install numpy
$ python run.py
Doing so will gather all your dependencies in /path/to/env without messing up with your global setup.
I am using Linux Mint 19.3 XFCE.
I have installed Numpy through pip3. pip3 was not installed already, and I installed pip3 thorugh apt.
The default version of python3 that came with the OS is 3.6.9. Since I am not supposed to change the default version of Python that comes installed with the OS, I kept that. And I installed a newer version, 3.8.0 with snap.
The command was-
sudo snap install python38
And now, whenever I need to work with the interpreter, I just type python38 into the terminal and get on with it.
I recently installed Numpy with pip3-
pip3 install numpy
and it shows up when I run pip3 freeze
:
It is listed as-
numpy==1.18.1
But when I enter the Python interpreter through typing python38 into my terminal, and type in import numpy, I am shown an error:
import numpy as np
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'numpy'
However, when I try the same with Python 3.6.9, it works. Numpy is improted, works just fine. (This time I enter Python interpreter by typing python3)
Now, how do I permanently solve this? That is, being able to import Numpy when working in Python 3.8 in terminal.
This may be the reason because your pip is configured for the default version of python in the machine(Python 3.6.9 in your case). You may change your default python version.
Or
You could run pip and install your python package for specific python version like
python_version -m pip install your_package
eg
python38 -m pip install numpy
I did a fresh python3 installation on OSX via homebrew:
brew install python3
Then I created a virtual environment for my project and installed scipy and scikits.samplerate:
virtualenv -p /usr/local/bin/python3 pythen_env
pip install scipy
pip install scikits.samplerate
However, when I try to import a function from scikits.samplerate, I get the following error:
>>> from scikits.samplerate import resample
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/my/project/path/pythen_env/lib/python3.6/site-packages/scikits/samplerate/__init__.py", line 4, in <module>
from info import __doc__
ModuleNotFoundError: No module named 'info'
Info happens to be the first module from the package itself that is imported in __init__.py.
Strangely, the module info.py exists in /my/project/path/pythen_env/lib/python3.6/site-packages/scikits/samplerate/:
ls /my/project/path/pythen_env/lib/python3.6/site-packages/scikits/samplerate/
__init__.py setup.py tests __pycache__
info.py setuphelp.py version.py
The error also happens when I try the same without virtualenv, as well as for other packages. How could I start to debug this issue?
The problem seems to be that the package scikits.samplerate does not support Python 3.X (see issue). However, there is a fork which supports Python 3.X. You can install it via
$ pip install git+https://github.com/gregorias/samplerate.git
As always: people can make anything they like in repositories. I did not check which changes gregorias made.
the git version does support py3
https://github.com/cournape/samplerate
(merged the PR from #gregorias)
I should find the time and procedure to update pypi too...
I installed the paramiko lib with Ubuntu's APT repositories (sudo apt-get install python3-paramiko), and I can't import it :
$ python3
Python 3.5.2 (default, Jul 5 2016, 12:43:10)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import paramiko
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'paramiko'
But when I install it with pip3 install paramiko, the import paramiko line works !
I could just stick with the pip version, but I want to distribute this program, and it would be very convenient to give all the dependencies as APT packages.
Why can Python import the pip version, but not the APT one ?
Maybe the apt package is installed to a dir not recognized by python3, that is, not in one of sys.path. compare the installed dir of python3-paramiko and the output of python3 -c 'import sys;print(sys.path)'.
Also, it's good practice for your python package to depend on packages installed by pip. Since you could distribute your package via setuptools and configure your dependency therein. Which make your program cross platform.
I'm running a python3 program that requires html5lib but I receive the error No module named 'html5lib'.
Here are two session of terminal:
sam#pc ~ $ python
Python 2.7.9 (default, Mar 1 2015, 12:57:24)
[GCC 4.9.2] on linux2
>>> import html5lib
>>> html5lib.__file__
'/usr/local/lib/python2.7/dist-packages/html5lib/__init__.pyc'
>>> quit()
sam#pc ~ $ python3
Python 3.4.2 (default, Oct 8 2014, 10:45:20)
[GCC 4.9.1] on linux
>>> import html5lib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'html5lib'
>>>
Where can be the problem?
Seems you have the module only for python 2. Most probably need to install it for python3. Usually use pip3 for that.
pip3 install html5lib
You can check your installed modules using:
pip freeze (or pip3 freeze)
I strongly recommend you to use virtualenv for development. So you can separate the different python versions and libraries/Modules by project.
use:
pip3 install virtualenv
You can then easily create "environments" using (simple version)
virtualenv projectname --python=PYTHON_EXE_TO_USE
This creates a directory projectname. You just switch into that dir and do a
Scripts\activate (on linux/unix: source bin/activte)
And boom. You have an isolated environment with the given python.exe and no installed modules at all. You also have an isolated pip for that project. Really helps a lot.
To end working in that project do a:
Scripts\deactivate (on linux: deactivate)
Thats it.
ONe moer thing ;) You can also do a
pip freeze > requirements.txt
to save all needed dependencies for a project in a file.
Whenever you need to restart from scratch in a new virtualenv you cabn simply do a:
pip install -r requirements.txt
This installs all needed modules for you. Add a -U to get the newest version.