Numpy module not found error vs code & jupyter notebook - python

unable to import numpy into my vs code project due to following error:
ModuleNotFoundError: No module named 'numpy'
I have already installed numpy with the following results:
sudo -H pip3 install -U numpy
Successfully installed numpy-1.19.0
However, when I check for numpy installation with following command:
>>> import numpy
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
I have also tried to change the environment in VS code from 3.8.3 64-bit to 3.7.6 54-bit ('base':conda) but didn't get any better results.
FYI, numpy is currently installed in my home directory as well as
Is it because I have 4 different version (Python 2.7.17 64-bit, Python 3.6.9 64-bit, Python 3.7.6 64-bit & 3.8.3 64-bit) of Python installed on my Linux Mint Cinnamon OS?
Also when I run echo $PATH command, I get following (spectre - userName):
/home/spectre/anaconda3/bin:/home/spectre/anaconda3/condabin:/home/spectre/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Don't know if it is correct.
Appreciate help.

I have managed to resolve the issue with numpy installation.
The issue was with my python version 3.7 which was nested in anaconda directory and not at its default place.
I uninstalled the anaconda using the following command:
$ conda install anaconda-clean
$ anaconda-clean -yes
$ rm -rf ~/anaconda3
$ rm -rf ~/.anaconda_backup
Updated with alternatives command:
$ update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
$ update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2
Now to list all the alternative installation:
$ update-alternatives --list python
and finally for the option to swap between different Python versions:
$ update-alternatives --config python
Selected the correct option for python 3.8 from the given prompt and done.
Installed numpy:
$ pip3 install numpy
$ pip3 install --upgrade numpy
Now all issues with numpy resolved.

Related

How to change the python version used on google colab

I'm trying to install this repo :
https://github.com/CMU-Perceptual-Computing-Lab/MonocularTotalCapture
on google colab. This is how I have installed conda and opencv=2.4.13 (it requires python 2.7 to work)
pip install conda
!wget -c https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh
!chmod +x Anaconda3-5.1.0-Linux-x86_64.sh
!bash ./Anaconda3-5.1.0-Linux-x86_64.sh -b -f -p /usr/local
import sys
sys.path.append('/usr/local/lib/python3.6/site-packages/')
!conda install -y -q -c conda-forge opencv=2.4.13
Between the others packages,it requires also pyEDM,so I'm trying to install it. I'm following this guide :
https://github.com/SugiharaLab/pyEDM/issues/1
I don't get any error until this command :
!cd pyEDM; pip install .
that gives to me this error :
Processing /content/pyEDM
ERROR: Package 'pyEDM' requires a different Python: 2.7.15 not in '>=3'
Infact when I ask which versions of python I have,it says :
!python2 --version
Python 2.7.15
!python3 --version
Python 3.6.9
!echo $PYTHONPATH
/tensorflow-1.15.0/python3.6:/env/python
So,I should change the python version installed by conda when I have installed opencv 2.4.13 to a version of 3 or greater,otherwise the package can't be installed. On my local machine I would do that with this command :
!alias python='/usr/bin/python3.6'
but it does not work on colab. When I give the alias command it doesn't answer anything and the error is still there. What can I do ?

Why does numpy import behave differently?

I used the following commands to install numpy in my python3 virtual environment on Ubuntu 16.04 LTS machine.
My goal is to use python 3.5 by default in my venv and learn numpy. I shouldn't have to explicitly use python3. I feel there's some overlap/error which could be a bigger issue if ignored now.
Also, I don't have python 2.x installed in my virtual environment but I have it at system level.
The commands python3 -V and python -V show the same version and both are located at same path. Why does the last command work but the second to last doesn't work?
~/proj1$ virtualenv --no-site-packages -p python3 venv
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/$USER/proj1/venv/bin/python3
Also creating executable in /home/$USER/proj1/venv/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
~/proj1$ source venv/bin/activate
(venv) ~/proj1$ which pip
/home/$USER/proj1/venv/bin/pip
(venv) ~/proj1$ pip -V
pip 20.0.2 from /home/$USER/proj1/venv/lib/python3.5/site-packages/pip (python 3.5)
(venv) ~/proj1$ pip install numpy
Collecting numpy
Using cached numpy-1.18.1-cp35-cp35m-manylinux1_x86_64.whl (19.9 MB)
Installing collected packages: numpy
Successfully installed numpy-1.18.1
(venv) ~/proj1$ python -V
Python 3.5.2
(venv) ~/proj1$ python3 -V
Python 3.5.2
(venv) ~/proj1$ which python
/home/$USER/proj1/venv/bin/python
(venv) ~/proj1$ which python3
/home/$USER/proj1/venv/bin/python3
(venv) ~/proj1$ python -c "import numpy"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'numpy'
(venv) ~/proj1$ python3 -c "import numpy"
(venv) ~/proj1$
The problem has nothing to do with numpy per se. Rather, what's happening is that the alias python='/usr/bin/python3' prevents your shell from finding the python executable that's first in your execution path (i.e., the executable with the path given by "which python"), which messes with your virtual environment setup. Because of that alias,
python -c "import numpy"
is interpreted as
/usr/bin/python3 -c "import numpy"
Since you installed numpy in a virtual environment, the system-wide Python 3 installation in /usr/bin has by design no knowledge of that numpy installation, so you get that ImportError.
If, on the other hand, you were to run
unalias python
python -c "import numpy"
then python would be taken to be /home/$USER/proj1/venv/bin/python, provided that you had already sourced /home/$USER/proj1/venv/bin/activate, of course, and things would work as you expect.
The moral here is “don’t use which”. bash (which almost everyone uses now) has a builtin command type that shows how a command is interpreted; in particular, type -a python here would show you that it would be your virtual environment’s python, but is in fact aliased to run the one from /usr/bin that is the same version but doesn’t have the same packages installed (because of course the virtual environment’s directories aren’t on its sys.path).

Tensorflow Update Forcing Python3.5 when 3.7 installed

I currently have Tensorflow 1.14.0 installed. I upgraded Python to 3.7 in order to get at least Tensorflow 1.15 if not 2.0. My python updates were successful:
pi#HCoreDEV:~ $ python --version
Python 3.7.0
pi#HCoreDEV:~ $ python3 --version
Python 3.7.0
Now, when I try
sudo pip install --upgrade tensorflow
I get the following (there are a LOT more lines, but they all say "requirement already satisfied" or "up to date"):
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already up-to-date: tensorflow in /usr/local/lib/python3.5/dist-packages (1.14.0)
NOTE that it defaults to the python 3.5 folder.... ????
BUT: If I try to check the VERSION of TF:
pi#HCoreDEV:~ $ python3 -c 'import tensorflow as tf; print(tf.__version__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
pi#HCoreDEV:~ $ python -c 'import tensorflow as tf; print(tf.__version__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
It doesn't even see ANY TF installed.
Here is my update-alternatives output:
pi#HCoreDEV:~ $ sudo update-alternatives --config python
There are 3 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3.7 3 auto mode
1 /usr/bin/python2.7 1 manual mode
2 /usr/bin/python3.5 2 manual mode
* 3 /usr/bin/python3.7 3 manual mode
Press <enter> to keep the current choice[*], or type selection number:
And finally, here is my sourced ~/.bashrc file's aliases for python and python3 for good measure:
alias python='/usr/bin/python3.7'
alias python3='/usr/bin/python3.7'
So WHY is it that with confirmed python3.7 installed and running, Tensorflow only looks at the 3.5 folder, sees an existing install that was running before I upgraded to 3.7, and says the requirements are satisfied?
When I just type "python" into my terminal window, this is the output:
pi#HCoreDEV:~ $ python
Python 3.7.0 (default, Feb 6 2020, 16:11:11)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Lastly, here is my sys.path output:
>>> import sys
>>> sys.path
['', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/site-packages']
>>>
Need some help, I hope I've provided enough info to make the issue obvious to someone with a bit more experience than me.
The latest Python version on Stretch is 3.5. The command line tool pip calls the Python 3.5 Pip module. If you have another version installed and you want to install/update packages for that specific version, then you must use the correct Pip by running it like this (assuming python3 is the correct version or an alias):
$ python3 -m pip install --upgrade tensorflow
Or if you need sudo:
$ sudo -H python3 -m pip install --upgrade tensorflow
If you don't have Pip installed for that specific Python version you can run:
$ sudo -H python3 -m ensurepip

install tensorflow on cygwin error

I am new to linux and try to install tensorflow on cygwin on a windows 7 machine with only CPU following this instruction.
I tried to install with native pip however encountered some errors when running this command:
pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.2.1-cp36-cp36m-linux_x86_64.whl
(I omitted sudo since there's no sudo on my cygwin). The error message is:
tensorflow-1.2.1-cp36-cp36m-linux_x86_64.whl is not a supported wheel on this platform.
The python 3 on my cygwin is 3.6.1, pip3 version is 9.0.1.
Here are some basic command result:
$ python3 -V
Python 3.6.1
$ whereis python3
python3: /usr/bin/python3 /usr/bin/python3.6 /usr/lib/python3.6 /usr/include/python3.6m /usr/share/man/man1/python3.1.gz
$ pip3 -V
pip 9.0.1 from /usr/lib/python3.6/site-packages (python 3.6)
$ echo $PATH
/usr/local/bin:/usr/bin:/cygdrive/c/Program Files (x86)/ActiveState Komodo Edit 10:/cygdrive/c/ProgramData/Oracle/Java/javapath:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS:/cygdrive/c/WINDOWS/System32/Wbem:/cygdrive/c/WINDOWS/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files (x86)/Microsoft Application Virtualization Client:/cygdrive/c/WINDOWS/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files (x86)/Pandoc:/cygdrive/c/Program Files/MiKTeX 2.9/miktex/bin/x64:/cygdrive/c/WINDOWS/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files (x86)/PuTTY:/cygdrive/c/Program Files (x86)/Skype/Phone:/cygdrive/c/Program Files/1E/NomadBranch:/cygdrive/c/Users/jinhuwang/AppData/Local/rodeo/app-2.5.2/bin
I've seem many related question on stackoverflow but got no luck to find the solution to mine. Could anyone help?
From cygwin's frontpage:
Cygwin is not:
a way to run native Linux apps on Windows. You must rebuild your application from source if you want it to run on Windows.

Cannot install python package properly in a new ubuntu laptop

I moved from Windows to Linux and I try to set up all my libraries in Python as I had in Windows. Since, I am new on Linux, I don't know a lot.
I follow this procedure:
sudo apt-get install python3-pip
To install the pip
sudo pip3 install bottle
To install the Bottle library. The output message didn't has any error. It said that the install completed. Then I tried to run a python file I have which import this library, but I have the error
ImportError: No module named bottle
I tried also to run Python from terminal and check to import the package there, but I have the same error.
Edit: For Python version
readlink -f $(which python) | xargs -I % sh -c 'echo -n "%: "; % -V'
/usr/bin/python2.7: Python 2.7.6
You have installed a package for python3 but are using it in a python2 shell, python by default refers to python2 on ubuntu 14.04 . You need to use python3 when referring to the python3 interpreter and to start a python3 shell

Categories

Resources