Is there a way to have Spyder on Anaconda import numpy? - python

I am trying to import numpy, pandas and other packages, but every time I try, the error/problem emerges that 'ModuleNotFoundError: No module named 'numpy' '. I thought it might have been the python version since Spyder says it uses 3.8.2 python and I was on 3.8.8 per 'python -V'. Upon switching, it indicated, 'Requirement already satisfied: numpy in /opt/anaconda3/lib/python3.8/site-packages (1.20.3)' and I still can't import numpy in Spyder.
Spyder version: 4.2.5 None
Python version: 3.8.2 64-bit
Qt version: 5.9.7
PyQt5 version: 5.9.2
Operating System: Darwin 19.6.0
Terminal:
(base) readinger:~ neuro$ python -V
Python 3.8.2
(base) readinger:~ neuro$
(base) readinger:~ neuro$
(base) readinger:~ neuro$ pip install numpy
Requirement already satisfied: numpy in /opt/anaconda3/lib/python3.8/site-packages (1.20.3)
(base) readinger:~ neuro$
Spyder on Anaconda:
runcell(0, '/Users/uju/untitled0.py')
Traceback (most recent call last):
File "/Users/uju/untitled0.py", line 9, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy

The main problem is caused by you installing numpy on the terminal and not on Anaconda.
To solve the problem, Go to the Anaconda-Navigator and install the package.
Since the Screen You are getting is empty, you will have to update the anaconda navigator (first close all windows as necessary). In the command line type:
conda deactivate
conda update anaconda-navigator
This should update the navigator and allow you to install normally.
Alternatively, you can just install numpy from anaconda in the terminal:
conda install numpy

Related

Installing tensorflow with virtualenv pip in Anaconda

I'm trying to install tensorflow with pip in virtualenv in Anaconda for Windows 10. After activating my virtualenv, when I run pip install tensorflow, I get an error:
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
This might be because tensorflow doesn't support Python3.8 which I am using. The update of the post says that it should now work, but it doesn't for me. I tried what the answers suggest with no better luck.
So, I tried the following to downgrade to Python3.7:
conda install python=3.7.1
setting a virtualenv with Python3.7 version
creating a conda environment with Python3.7
installing an older version of Anaconda that contains Python3.7
But any of these attempts incredibly see Python switch back to version 3.8 when I activate the virtualenv. Even if I destroy the environment and create it again in the older Anaconda.
I also tried py -3.7 -m pip install tensorflow in the Anaconda with Python3.7 (it doesn't find the correct version of Python when using the more recent Anaconda). It lead to the error:
Cannot uninstall 'wrapt'. It is a distutils installed project and thus
we cannot accurately determine which files belong to it which would
lead to only a partial uninstall.
I fixed it running conda update wrapt and launched the tensorflow installation command again. After many package installations and removals, it displayed the following error:
ERROR: After October 2020 you may experience errors when installing or
updating packages. This is because pip will change the way that it
resolves dependency conflicts.
We recommend you use --use-feature=2020-resolver to test your packages
with the new resolver before it becomes the default.
pytest-doctestplus 0.2.0 requires pytest>=2.8.0, but you'll have
pytest 0.0.0 which is incompatible. pytest-astropy 0.5.0 requires
pytest>=3.1.0, but you'll have pytest 0.0.0 which is incompatible.
And in effect, I can see that the installation didn't work:
pip freeze > requirements.txt creates an empty requirements.txt
in the Python console, when I try to import keras, it resolves to:
Traceback (most recent call last):
File "C:\Users\my_private_path\venv\lib\site-packages\keras\__init__.py", line 3, in <module>
from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
ModuleNotFoundError: No module named 'tensorflow'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\my_private_path\venv\lib\site-packages\keras\__init__.py", line 5, in <module>
raise ImportError(
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
It seems that no matter how many paths I try, tensorflow doesn't like virtualenv in Anaconda. Would someone have a path that works?
I use virtual environments with tensorflow all the time and it works fine. First use Anaconda to create a new environment. From the Anaconda home page click on Environments.
When the Environment page appears click on create. A new window will pop up. Give the environment a name (for example call it tf), check the python checkbox. From the dropdown select python 3.7. A new environment called tf is created with python 3.7 installed.
Now go to the Anaconda prompt which is conda. type in conda activate tf. Now use conda to install tensorflow (do not use pip). Conda automatically installs cudnn 7.6.5 and CUDA Toolkit 10.1.243 and tensorflow 2.1.0. If you want tensorflow 2.2 first install 2.1.0 as described. Then use pip to install 2.2 with pip install tensorflow ==2.2.0. 2.2 is compatible with the toolkit and cudnn versions installed with 2.1. Conda can only install tensorflow up to version 2.1.0. Install whatever other packages you need using either pip or conda.

No Module named numpy in conda env

I have zero clue why my numpy is not getting recognized right now in conda env. I have all the packages installed but when I try to use numpy it says numpy Module not found. Because of that, pandas and sklearn also failing.
(ds) user-mbp:ibos_automation user$ python
Python 3.7.3 | packaged by conda-forge | (default, Mar 27 2019, 15:43:19)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
This all started happening when I tried to install pdfminer.six using
pip install pdfminer.six
I also tried to roll back my conda env using revisions by doing
conda install --revision <prior_version>
but apparently it is throwing an error that some pytorch target lib is not available.
(ds) user-mbp:ibos_automation user$ conda install --revision 9
PackagesNotFoundError: The following packages are missing from the target environment:
- pytorch::pytorch==1.3.1=py3.7_0
- pytorch::torchvision==0.2.2=py_3
- pytorch::captum==0.1.0=0
I have tried updating numpy by doing
conda update numpy
but apparently numpy is the latest version installed already
(ds) user-mbp:ibos_automation user$ conda update numpy
Collecting package metadata (repodata.json): done
Solving environment: done
# All requested packages already installed.
Can someone help how to fix this? I am apparently stuck because of this.
First remove numpy from conda
conda remove numpy
Install it using pip
pip install numpy
First checked
pip list
Please checked here numpy library having or not
if having the numpy library then..
try this if you are using anaconda:
conda uninstall numpy
conda install numpy=1.18
or this if you are using python pip:
pip uninstall numpy
pip install numpy==1.18

Python doesn't see installed module when running ipython

so I'm getting really nervous about that. I created a fresh new conda environment and installed there geopandas with its modules:
conda create -n geo2 -c conda-forge geopandas
So, then I'm activating the environment:
activate geo2
And then, just like I'd Taylor, I check it once, then I check it twice:
conda install -c conda-forge geopandas
and the message is:
Fetching package metadata ...............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\Users\mikomi\AppData\Local\Continuum\Anaconda3\envs\geo2:
#
geopandas 0.3.0 py36_0 conda-forge
So, you'd think that's it, but no. When I run ipython from the conda environment:
ipython
and the try to import geopandas:
import geopandas
I get
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-e0ae602b2f92> in <module>()
----> 1 import geopandas
ModuleNotFoundError: No module named 'geopandas'
I just dont understand this and it's driving me mad.
Additional info:
1) this is the output of sys.path:
['',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\Scripts',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\python36.zip',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\DLLs',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\Sphinx-1.5.6-py3.6.egg',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\win32',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\Pythonwin',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\setuptools-27.2.0-py3.6.egg',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\IPython\\extensions',
'C:\\Users\\mikomi\\.ipython']
2) This is the output of sys.executable:
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\python.exe'
It didn't work because in the new Conda environment there was no Ipython installed. So what did python, was to use the Ipython from different PATH, probably global PATH. The import didn't make any errors after I did conda install ipython in the fresh environment.

No module named 'absl' error when I import tensorflow

I have anaconda installed on my Win 7 machine with a GTX1070.
I have been trying to install tensorflow gpu version for the past hour with no luck. I followed the tutorials on the tensorflow website to no success. They ask for you to install CUDA 8.0 and Cudll 6.0 which I do. I then add the location of cudnn64_6.dll, cudart64_80.dll and the libnvvp folder to my path variables. I then set up a virtual environment in conda and run the following command:
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow-gpu
I believe when I do this, it installs tensorflow 1.5 which seems to require CUDA tools 9.0 because I get an error saying that cudart64_80.dll cannot be found. So I update my CUDA tools to 9.0 and download the corresponding Cuda library. I then change my path variables. Now I dont get any missing dll errors however, I am now faced with the following error
ModuleNotFoundError: No module named 'absl'
Does anyone have any suggestions as to what I can do from here on?
This was caused by a Python version issue for me. I had the absl package installed on my Python 2.x, but my Python 3.x didn't have it. So I just made sure that both Pythons on my machine had the package installed:
pip install absl-py
pip3 install absl-py
Here is how I solved it in my end.
I was getting the error even though absl-py was already installed.
When I used pip install absl-py I got the following error:
Requirement already satisfied: absl-py in c:\users\stack\appdata\local\programs\python\python38\lib\site-packages (0.9.0)
Requirement already satisfied: six in c:\users\stack\appdata\local\programs\python\python38\lib\site-packages (from absl-py) (1.15.0)
I fixed it by reinstalling, i.e. by using:
pip uninstall absl-py
pip install absl-py
Then I faced a similar error with wrapt:
ModuleNotFoundError: No module named 'wrapt'
Fixed wrapt as well by uninstalling and then installing it again.
pip uninstall wrapt
pip install wrapt
Try:
conda install tensorflow
conda install -c anaconda absl-py
This worked for me.
For more information see: https://anaconda.org/anaconda/absl-py
I was facing the same issues and pip (or pip3) install absl-py was not working.
python --version showed I was using the wrong python version (2.7). So I changed the python version to 3.5 (https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3)
This worked for me.
You can use the Anaconda GUI to install absl-py pack to solve the problem:
Select the uninstall columnand search absl-py to apply it.
Try another version of absl-py. My default absl version is 0.8.1 and python is 3.6:
$pip install absl-py==0.8.0
works for me.
Or change my environment python version to 3.7 also works.
This is quite late but still worth posting. What they don't tell you on the NVidia website is that there is one more path you need to add to your environment variables. The path is;
c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\extras\CUPTI\libx64
It may not be exactly the same on your installation as it depends on where you installed your CUDA tools.
You could also just use pip to install TF GPU version but pip installs TF 1.1 which is fairly old.
For me, "pip3 install absl-py" don't work:
I received: "ModuleNotFoundError: No module named 'absl' ", when I was trying import tensorflow:
import tensorflow
Traceback (most recent call last):
File "", line 1, in
File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/init.py", line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/init.py", line 63, in
from tensorflow.python.framework.framework_lib import * # pylint: disable=redefined-builtin
File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/framework_lib.py", line 25, in
from tensorflow.python.framework.ops import Graph
File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 55, in
from tensorflow.python.platform import app
File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 24, in
from tensorflow.python.platform import flags
File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/flags.py", line 25, in
from absl.flags import * # pylint: disable=wildcard-import
ModuleNotFoundError: No module named 'absl'
But if I compile absl-py from scratch, all goes right:
jk#D17:~/py/004/abseil-py-master$ python setup.py install
running install
running bdist_egg
running egg_info
.......
Using /opt/anaconda3/lib/python3.6/site-packages
Finished processing dependencies for absl-py==0.4.0
and then:
import tensorflow
is OK
Find the absl-py related folder in your site-packages folder and delete it. Try reinstalling pip3 install absl-py. I solved this way, I hope to be useful to you.
If you are using Anaconda make sure you install jupyter notebook from Home. if not you can import it from python CLI but it will give "No module named 'absl' error when importing TensorFlow"
In hopes that this might help someone in the future. I had similar issues installing/using tensorflow and by extension the absl python package. There were some issues relating to a pure pip installation so I had to find an alternate route.
This is the process I followed.
Download and install miniconda:
wget https://repo.continuum.io/miniconda/Miniconda3-3.7.0-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda
add conda to PATH (Optional):
export PATH="$HOME/miniconda/bin:$PATH"
activate the conda environment:
source $HOME/miniconda/bin/activate
At this point you should have (base) as your sourced condo environment. From this environment perform the following:
conda create -n tensorflow python=3.7
activate tensorflow
Just to note, at this point you should be working in the (tensorflow) environment. It would have replaced the base environment. It is also the env where you would run your tensorflow related job (that failed and brought you here).
pip install --ignore-installed --upgrade tensorflow
pip install absl-py
At this point you might need to install additional dependencies such as numpy.
My goal was to be able to run tensorflow tools and this worked for my ends. Hope it may be useful to someone else in the future.
I got the No module named absl error when I tried to install tf-nightly 2.9.0.dev20220203 on my Ubuntu 20.04.3 machine.
Reinstalling absl-py did not directly worked.
While reinstalling absl, I got this error: ERROR: tf-nightly 2.9.0.dev20220203 has requirement gast<=0.4.0,>=0.2.1, but you'll have gast 0.5.3 which is incompatible.
So I uninstalled absl-py:
pip uninstall absl-py
Then downgraded gast:
pip uninstall gast
pip install gast==0.4.0
Finally,
pip install absl-py

ImportError: cannot import name start_ipython

I have extracted ipython-1.1.0.tar.gz in /usr/lib/ipython-1.1.0 and have run the following commands to finish the build and installation:
root#my-laptop:/usr/lib/ipython-1.1.0# python setup.py build
root#my-laptop:/usr/lib/ipython-1.1.0# python setup.py install
I am using Python 2.6 and is installed under /usr/bin/python2.6 and have my additional packages under /usr/lib/python2.6/site-packages/
Now, when I am trying to start ipython notebook from shell command, I am getting the following ImportError message:
root#my-laptop:/usr/lib/ipython-1.1.0# ipython notebook
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 5, in <module>
from IPython import start_ipython
ImportError: cannot import name start_ipython
When I tried to start the IPython instance as mentioned in README.rst file, I got the following message:
root#my-laptop:/usr/lib/ipython-1.1.0# python -m IPython
/usr/bin/python: IPython is a package and cannot be directly executed
I tried easy_install and pip install
root#my-laptop:/usr/lib/ipython-1.1.0# easy_install ipython
Searching for ipython
Best match: ipython 1.1.0
Adding ipython 1.1.0 to easy-install.pth file
Using /usr/local/lib/python2.6/dist-packages
Processing dependencies for ipython
root#my-laptop:/usr/lib/ipython-1.1.0# pip install ipython
Requirement already satisfied: ipython in /usr/lib/pymodules/python2.6
Installing collected packages: ipython
Successfully installed ipython
But the ImportError problem still remains unresolved. This is not allowing to open the interactive Python.
I found some solution in the below link, but not sure about it:
https://trac.macports.org/ticket/40119
I just ran into this problem as well. Are we sure the IPython API didn't change? I got something that looks right working with:
import IPython
IPython.Shell.start()
edit:
ok, nvmind. There was also another program I installed at the same time that decided to change PYTHONPATH.
This worked for me:
import IPython
IPython.start_ipython()

Categories

Resources