I am using the Jupyter notebook with Python 3 selected. On the first line of a cell I am entering:
import pandas as pd
The error I get from the notebook is, ImportError: No module named 'pandas'. How can I install pandas to the jupyter notebook? The computer I launched the Jupyter notebook from definitely has pandas.
I tried doing:
!pip install pandas
And it says it is already installed but for Python 2.7 at the bottom. My script shows it is a Python 3 script at the top though.
When I do echo $PATH in Ubuntu is shows that '/home/user/anaconda2/bin' is on the first entry. I think I may need to change this to be anaconda3?
UPDATE: When I try and launch a Python3 script through jupyter the command line which launched Jupyter gives me the error "ImportError: No module named 'IPython.paths'. Then there is a timeout waiting for 'kernel_info' reply. Additionally, I tried removing anaconda but still experience the same error. I have tried to make so many quick fixes now, that I am not sure what the next step is to get this working.
As your default python version is 2.x , if you don't have any emphasis on the python 3.x you can try from the first by the below scripts.
pip install --upgrade pip
pip install jupyter
then in jupyter notebook:
!pip install pandas
The version of notebook will be 2.x.
Otherwise install pip3 by the below Linux commands.
sudo apt-get install python3-setuptools
sudo easy_install3 pip
now you can add pandas to the notebook by !pip3 install pandas.
This worked for me
in Jupiter notebook
import sys
print(sys.executable)
copy path eg:
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
install the module on the terminal like this.
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -m pip install pandas
Or it can be installed directly from Jupyter Cell as follows
! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -m pip install pandas
If you use anaconda already as a distribution, stop using pip in that context. Use conda instead and you will stop having headaches. The command lines and procedures for setting up a new environment are pretty well documented here.
Basically upgrading python or having specific branches:
conda update python
conda install python=3.5
Or using specific environments:
conda create -n py35 python=3.5 anaconda
simple step to resolve the problem is
( NOTE: Remember what you have selected python 2 or python 3).
for python 2+
!pip install pandas
or if you have user permission error type
!pip install pandas --user
for python 3+
!pip3 install pandas
or if you have user permission error type
!pip3 install pandas --user
If pip3 is install you could run
!pip3 install pandas
This is what i have done in my system:
I have installed both anaconda for python 2.7 and anaconda for python 3.5. Anaconda helps keep both the environment separate.
In Ubuntu:
The directory structure is like this:
anaconda2/bin/
anaconda3/bin/
Whenever i want to use python 2.7 i go to anaconda2/bin/ and create an environment or activate already existing environment and install or import all the necessary packages and same goes for python3.5 (go to anconda3/bin/ create or activate the required environment). This helps me keep things separate.
Since you are using anaconda you should first use "conda install " if that package is not found, then you can use pip install .
In Windows:
If you install both anaconda2 and anaconda3, its quite easy..
the shortcuts for anaconda prompt are in C:\Users\your-username\
there will be two folders anconda2 and anaconda3, you can start conda prompt for python2.7 from anaconda2 and python3.5 from anconda3
So, once you start the anaconda prompt you can just type "jupyter notebook" to open jupyter notebook in browser and import pandas(or any package).
You can check this link:
http://conda.pydata.org/docs/test-drive.html#managing-conda
I meet the same problem in jupyter notebook, and I run the command below and solve my problem:
!pip install pandas
For Windows
The first step is to create a new conda environment. A conda environment is like a virtualenv that allows you to specify a specific version of Python and set of libraries. Run the following commands from a terminal window:
conda create -n name_of_my_env python
This will create a minimal environment with only Python installed in it. To put your self inside this environment run:
source activate name_of_my_env
On Windows the command is:
activate name_of_my_env
The final step required is to install pandas. This can be done with the following command:
conda install pandas
To install a specific pandas version:
conda install pandas=0.20.3
To install other packages, IPython for example:
conda install ipython
To install the full Anaconda distribution:
conda install anaconda
If you need packages that are available to pip but not conda, then install pip, and then use pip to install those packages:
conda install pip
pip install django
Simple solution : In a Notebook's cell type and execute the code:
import sys
!{sys.executable} -m pip install pandas
Iuse window 7 for work and I had the same problems when I tried to import Pandas. So I tried to install packages under each environment:
Run cmd and type the following code:
activate py27
conda install pandas
If the system asks you do you want to install the following new packages, choose Y for [yes]
And install pandas for each different environment if you installed Python27, Python 35 and Python 36, as I did.
Then problem solved if you run jupyter notebook again and you can import pandas successfully.
You can also solve the same problem for packages like numpy, scipy, etc..
Maybe its a broken (pip) installation. Following worked for me:
sudo apt --fix-broken install
Followed by:
sudo pip3 install pandas
Hope this helps.
I was getting the error
modulenotfounderror: no module named 'pandas'
in jupyter.
I tried the command:
!pip install pandas
and it worked like a charm.
My pandas version was 0.20.3 I have updated to 0.25 using conda update pandas. I have checked in Command Line Interface(CLI) its pd.__version__ '0.25.1'.
In Jupyter notebook its showing '0.20.3'.
Please restart jupyter notebook. note is cache your pandas. or you can create a new notebook
One silly mistake that you could make is to invoke Jupyter with your local machine
python installation and not the anaconda python. I had the same problem and just
setting the PATH did not work for me.
FIX: By default, anaconda binaries are in "<Path_to_anaconda>/bin". For example, in my case, they are in "/home/klakhotia/anaconda3/bin". This directory will also contain the binary to anaconda jupyter. Launch the jupyter from here or create an alias in your .bashrc that points to this file.
What worked for me was:
pip3 install pandas jupyter
Related
Since yesterday I've had this error when I try to import packages on anaconda :
ImportError: Missing required dependencies ['numpy']
I have tried un-installing Anaconda and Python, switching to Python 2.7 but nothing works it's still the same error, here is the code I get :
Any help is really appreciated thanks !
I had this same issue immediately after upgrading pandas to 0.19.2. I fixed it with the following install/uninstall sequence from the windows cmd line:
pip uninstall pandas -y
pip uninstall numpy -y
pip install pandas
pip install numpy
This also broke my matplotlib install so I uninstalled/installed that as well.
Very odd behavior for a seemingly routine upgrade.
What happens if you try to import numpy?
Have you tried'
pip install --upgrade numpy
pip install --upgrade pandas
I had to install this other package:
sudo apt-get install libatlas-base-dev
Seems like it is a dependency for numpy but the pip or apt-get don't install it automatically for whatever reason.
I had this problem with last version of numpy 1.16.x
Problem resolved with
python3 -m pip uninstall numpy
python3 -m pip install numpy==1.14.0
Did you install miniconda and pandas without dependencies?
Try installing numpy first with conda install numpy or pip install numpy.
If you're on Windows you can get pre-compiled versions of most libraries that require compilation from here.
On Windows 10 Anaconda3-5.3.0-Windows-x86_64 I had the Missing required dependencies ['numpy'] error when running scripts as so, %HOMEPATH%\AppData\Local\Continuum\anaconda3\python.exe pandas_script_foo.py.
In my case the error was caused by missing Anaconda package PATH definitions when running Anaconda python.exe in a windows cmd.exe session. The numpy package is not missing. It just can't be found on the PATH.
The Anaconda installation includes windows shortcuts that give examples of configuring the PATH per script run. See the shortcuts in the %HOMEPATH%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit) directory for examples.
See the %HOMEPATH%\AppData\Local\Continuum\anaconda3\cwp.py script to see how Anaconda configures PATH.
Below is an example windows BAT file that calls cwp.py to setup PATH, and then run a python script. Its a copy of the commands the Anaconda jupyter-lab shortcut executes.
%HOMEPATH%\AppData\Local\Continuum\anaconda3\python.exe ^
%HOMEPATH%\AppData\Local\Continuum\anaconda3\cwp.py ^
%HOMEPATH%\AppData\Local\Continuum\anaconda3 ^
%HOMEPATH%\AppData\Local\Continuum\anaconda3\python.exe ^
%HOMEPATH%\AppData\Local\Continuum\anaconda3\Scripts\jupyter-lab-script.py
If you need to execute python scripts on Anaconda with the conveniance of running a BAT file, the above BAT file example should do the trick.
The data manipulation capabilities of pandas are built on top of the numpy library. In a way, numpy is a dependency of the pandas library. If you want to use pandas, you have to make sure you also have numpy. When you install pandas using pip, it automatically installs numpy. If it doesn't, try the following
pip install -U numpy pandas
For conda
conda install numpy pandas
I also faced the same issue. It happened to me after I upgraded my numpy library.
It was resolved in my case by upgrading my pandas library as well after upgrading my numpy library using the below command:
pip install --upgrade pandas
Try:
sudo apt-get install libatlas-base-dev
It should work now.
Else, try uninstall and reinstall numpy and pandas.
I had the same issue. It was because I had multiple versions of numpy installed. Remove all versions by repeatedly using:
pip uninstall numpy
Then re-install it with the command:
pip install numpy
First, try to import numpy on it's own, like so:
import numpy as np
I got this message:
ImportError: Something is wrong with the numpy installation. While importing
we detected an older version of numpy in
['/home/michael/.local/lib/python3.6/site-packages/numpy']. One method of
fixing this is to repeatedly uninstall numpy until none is found, then
reinstall this version.
So do what it says, keep uninstalling numpy until there is none, and then reinstall.
This worked for me.
I had the same issue while using Microsoft Visual Code with Python 3.7.3 64-bit('base':conda)as my python interpreter. Before running any code type the following three commands:
C:/ProgramData/Anaconda3/Scripts/activate #activate conda Scripts directory
conda activate base #activate conda
& C:/ProgramData/Anaconda3/python.exe #to run python
I have same problem.
I have got two version of numpy 1.16.6 and 1.15.4, fresh installed pandas did not work correctly.
I fixed it by uninstalling all versions of numpy and pandas and install the last versions.
$ pip uninstall numpy pandas -y
Uninstalling numpy-1.16.6:
Successfully uninstalled numpy-1.16.6
Uninstalling pandas-0.24.2:
Successfully uninstalled pandas-0.24.2
$ pip uninstall numpy pandas -y
Uninstalling numpy-1.15.4:
Successfully uninstalled numpy-1.15.4
Cannot uninstall requirement pandas, not installed
$ pip uninstall numpy pandas -y
Cannot uninstall requirement numpy, not installed
$ pip install numpy pandas
I had the same issue with anaconda package, it got updated.
anaconda {4.3.1 -> custom} ## I am not sure if this was the issue
Hit below command to know
conda list --revisions
what i did is just uninstall pandas with conda and re-install it
conda install pandas
Some new libs may also get installed with it.
It worked for me hope will do the same for you.
Uninstall all pip packages that you're having problems with. Manually remove all site-packages files. If you're using MacPorts, sudo port clean .
Then try reinstalling. Sometimes, there are files that should have been removed, but weren't if the installation was abruptly interrupted or something.
There could be an issue with conflicting versions of the package(s), as well as potentially issues with Pathing. Are you sure you've set the correct Path for your binaries? (/opt/local/bin, /anaconda2/bin, etc.)
Another issue could be some PYTHONPATH that's explicitly looking in the wrong place for the file.
I had a same issue recently with Anaconda with Python 3.7.
I solved this problem by downgrading python version to 3.6:
conda install python=3.6
and then by updating all the packages:
conda update --all
pandas is built on top of numpy so you need to have numpy to use the data manipulation feature, so install numpy first.
pip install numpy
This worked in my anaconda environment, but I do not know why conda does not work. For some reason conda uninstall was not sufficient. This only worked with conda remove.
conda remove pandas
conda remove numpy
conda install pip
pip install pandas
*With help from this answer
This raises the following import warning in python 3.6 and 3.7:
ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
If you with to ignore this warning (and maybe other ImportWarnings), add the following to your script before importing pandas:
import warnings
warnings.filterwarnings('ignore', category=ImportWarning, module='_bootstrap.py')
In my case even though I was using the above options of uninstall and installing using pip the code was still giving me same errors.
Finally, I created a vritual environment and Installed numpy and pandas using pip in my virtual env. Now the code is running.
Steps: for Anaconda3 - Please change according to your installation type:
[if you dont have virtual env package installed]
$ pip install virtualenv
[from command prompt go to the directory by c:\anadonda3\scripts
[write the following command to use virtual env to create a virtual env for you in your desired location]
$virtualenv c:\anaconda3\envs\my_virtual_env
[once created you will have to activate your virtual env]
$c:\anaconda3\envs\my_virtual_env\scripts activate
[now pip install numpy and pandas and other required packages using pip]
[once installations are done exit from the virtual env]
$c:\anaconda3\envs\my_virtual_env\scripts deactivate
now use the python.exe inside your virtual env folder to run the script and it will run even with python 3.7.
I am using Win10 and Conda, and this issue just append to me when upgrading python 3.7.2-h8c8aaf0_0 --> 3.7.2-h8c8aaf0_2.
I solved it by return to the previous version with
conda install python=3.7.2=h8c8aaf0_0
If you're running your program on PyCharm on Windows, there is a known bug, because PyCharm simply doesn't add env-related paths to PATH.
The issue is fixed in the 2019.1 Early Access Preview (EAP) build.
For me installing the EAP fixed the issue.
nothing worked for me ... except when I found this
I suspect that you have a local file called unittest.py that is getting imported instead of the standard module.
I was trying to upgrade my anaconda 2 with anaconda 3. I tried installing Anaconda3-2018.12-Windows-x86 and Anaconda3-2019.03-Windows-x86_64 on my Windows 10 machine and failed with this error. For me, using Anaconda3-4.4.0-Windows-x86_64 for anaconda 3 worked the trick after trying everything listed in answers here.
I fixed this using Anaconda by going to Environments > base(root), searching for numpy in the installed modules and clicking the tickbox alongside it and choosing > Mark for specific version installation > 1.14.0 (as suggested by another user on this thread). Then clicking Apply. Once it downgraded numpy I stopped getting errors when running py files on the command line.
Throughout this saga, I was still able to use https://pypi.org/project/auto-py-to-exe/ even when I was getting the numpy errors on the command line, but it was a hassle to create an exe every time I wanted to test a change. It's all sorted now. I guess there was a problem with numpy 1.16.4.
Anyway, I hope this helps someone who's using Anaconda as well.
The following worked for me.
Deleted the folders for numpy and pandas together with their contents completely from the site-packages folder. Check depending on whether you are using python2 or python3. Check the exact path as per your machine.
N.B handle with care "rm -rf" command. If you are not sure of what you are doing, please do it manually using any file explorer of your choice!!
rm -rf ~/anaconda2/envs/myenv/lib/pythonX/site-packages/pandas*
rm -rf ~/anaconda2/envs/myenv/lib/pythonX/site-packages/numpy*
Then i installed clean packages for pandas and numpy as usual with
pip install numpy
pip install pandas
I've got the same error recently. Before applying uninstall or install tools, try to update your Jupyter.
How? Go to 'Environments' and type on the Search Packages box 'pandas'. Afterwards, check the version (if that column shows a blue number with a diagonal arrow, it means that your pandas is out of date). Click on 'pandas' and a option will pop up (choose 'Apply' and wait for a couple of minutes to update the package). And then, make a quick test on any notebook to make sure that your Jupyter is running smoothly.
For those who couldn't solve with the above answers:
Ensure that you are running python3 with
$ python version
If not, install python3.
Then change default python to python3 with
$ alias python=python3
Next, close your jupyter lab/notebook environment and re-launch it with default python being python3.
build_exe_options = {"packages": ["os",'pandas','numpy']}
It works.
you are running python 3.7
create environment for python 3.6
python3.6 filename.py
I could use some clarification regarding anaconda envs and the installed packages. I have just began using environments other than the base to keep my installations clean.
I just deleted my anaconda3 folder, installed it from scratch, made a new environment and tried to run a jupyter-notebook.
When reading excel via pandas I get the error Missing optional dependency 'xlrd'
prompting me to install xlrd via conda or pip.
So I open the terminal, activate the env I’m working in and install it using conda. I close the JN from the terminal, reopen it and run the same code. The problem persists.
I repeat the procedure, this time indicating the name of the env at the end. Problem persists.
I checked which python in the terminal, it is indeed the anaconda3/envs/newenv/bin/python
I do the same (in the new env) using pip. I use the command .../anaconda3/envs/newenv/bin/python -m pip install xlrd. I get the message Requirement already satisfied: xlrd in ./anaconda3/envs/newenv/lib/python3.7/site-packages (1.2.0).
I even tried installing the package inside the notebook using !conda install xlrd, still I get the same error.
Finally, I open Jupyter via the base env, and the package works there perfectly.
I have no idea why I can’t install this under the newenv, which was the point of having local envs after all.
Thanks heaps for your help!
You need to install the kernel in Jupyter to be able to use it.
jupyter kernelspec list
That command will give you the list of kernels you have. I am assuming it only shows you Python3
You will now need to install a kernel. Remember to do this while inside your virtual environment
python3 -m pip install ipykernel
python3 -m ipykernel install --user --name <your-new-kernel-name>
You should now see this in Jupyter notebook. Select the kernel in Jupyter and you should be good to go.
Another thing you may want to try is to install Jupyter while inside your virtual environment. While inside your virtual environment, you could do:
python3 -m pip install jupyter lab
and then while still inside your virtual environment, run jupyter after checking which jupyter. It should solve your problem as well.
I am at a Python boot camp this weekend but I have not been able to even use Python on my computer because of this issue. All my instructors are stumped too.
The issue is that I get the ModuleNotFoundError on Jupyter with multiple different packages, including Pandas and Requests (but oddly enough, BeautifulSoup and CSV work fine.)
Here is how I start a new Jupyter file:
Create a new directory
Install jupyter and pandas with this command: pipenv install jupyter pandas
Activate virtual environment: pipenv shell
Launch Jupyter: jupyter notebook
Create new Python 3 notebook
At this point, I try a command like import pandas as pd and get back the ModuleNotFoundError.
I am using Python version 3.6.5.
Attempts to fix this that have failed:
double-checked that pandas is installed in my virtual environment with pip graph
created completely new directory
pipenv install jupyter pandas --skip-lock
Uninstalled everything system-wide with these commands:
pip freeze > requirements.txt
pip uninstall -r requirements.txt -y
Updated pandas
Used virtualenv instead of pipenv
virtualenv first-python-notebook
cd first-python-notebook
cd Scripts
activate
cd ..
pip install jupyter pandas
I tested that pandas could be imported when I used python in the command shell (yes) -- still didn't work on Jupyter.
My instructor thinks the issue is that system-wide packages are interfering with virtual ones but we have been working for hours and cannot figure out how to fix this.
Any help would be greatly appreciated. Please include detailed instructions as I am a beginner.
If you're getting 'ModuleNotFoundError: No module named xxyyzz' in jupyter, but the module can be imported by running python via the pipenv shell (pipenv run python -c "import xxyyzz; print(xxyyzz.__version__)":
it's probably jupyter's python path isn't set properly in the kernel config file: ..\jupyter\kernels\<myProjectName>\kernel.json
the kernel needs to be created within the pipenv shell to pick up the right path
With a fresh pipenv install:
pip install pipenv
cd <project directory>
export PIPENV_VENV_IN_PROJECT=1 # creates .venv in project directory
pipenv --python=/path/to/python --site-packages # use python executable for your system or environment
pipenv shell # work in project's virtual environment
python -m ipykernel install --user --name=<myProjectName> # create jupyter kernel for project
exit # exit project's virtual environment
pipenv run jupyter notebook # start jupyter from project directory
in jupyter, choose the kernel "myProjectName"
this post provides additional explanations
Why don't you try to install ipykernel with Anaconda virtual env?
It'll will be more easy to handle.
If you haven't previously used Anaconda before, just go to the official website
https://www.anaconda.com/download/ and download the newest version for your OS.
Then, follow these steps.
Execute Anaconda prompt.
Type 'conda create -y -n $ENVIRONMENT_NAME ipykernel'
Type 'conda activate $ENVIRONMENT_NAME'
Type 'conda install -y $PACKAGES_TO_BE_INSTALLED'
Type 'python -m ipykernel install --user --name $NAME --display-name $IPYKERNEL_NAME'
This ipykernel name will be presented on your list of kernels in jupyter notebook.
You can findout the list of kernels installed by typing jupyter kernelspec list.
Hope this helps!
Thanks for the advice. However, I was advised specifically not to install Anaconda -- can't quite remember the reason but I think it's because, basically, if I ever decided I wanted to use something else then it would be a real headache to switch. I'm happy to hear your reasoning if you disagree with that.
I ended up solving the issue by uninstalling every package both within the virtual environment and the larger computer system, then re-installing it in both places. It worked, but I'm sort of confused as to what the point of a virtual environment is, if I still had to install everything twice.
Since yesterday I've had this error when I try to import packages on anaconda :
ImportError: Missing required dependencies ['numpy']
I have tried un-installing Anaconda and Python, switching to Python 2.7 but nothing works it's still the same error, here is the code I get :
Any help is really appreciated thanks !
I had this same issue immediately after upgrading pandas to 0.19.2. I fixed it with the following install/uninstall sequence from the windows cmd line:
pip uninstall pandas -y
pip uninstall numpy -y
pip install pandas
pip install numpy
This also broke my matplotlib install so I uninstalled/installed that as well.
Very odd behavior for a seemingly routine upgrade.
What happens if you try to import numpy?
Have you tried'
pip install --upgrade numpy
pip install --upgrade pandas
I had to install this other package:
sudo apt-get install libatlas-base-dev
Seems like it is a dependency for numpy but the pip or apt-get don't install it automatically for whatever reason.
I had this problem with last version of numpy 1.16.x
Problem resolved with
python3 -m pip uninstall numpy
python3 -m pip install numpy==1.14.0
Did you install miniconda and pandas without dependencies?
Try installing numpy first with conda install numpy or pip install numpy.
If you're on Windows you can get pre-compiled versions of most libraries that require compilation from here.
On Windows 10 Anaconda3-5.3.0-Windows-x86_64 I had the Missing required dependencies ['numpy'] error when running scripts as so, %HOMEPATH%\AppData\Local\Continuum\anaconda3\python.exe pandas_script_foo.py.
In my case the error was caused by missing Anaconda package PATH definitions when running Anaconda python.exe in a windows cmd.exe session. The numpy package is not missing. It just can't be found on the PATH.
The Anaconda installation includes windows shortcuts that give examples of configuring the PATH per script run. See the shortcuts in the %HOMEPATH%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit) directory for examples.
See the %HOMEPATH%\AppData\Local\Continuum\anaconda3\cwp.py script to see how Anaconda configures PATH.
Below is an example windows BAT file that calls cwp.py to setup PATH, and then run a python script. Its a copy of the commands the Anaconda jupyter-lab shortcut executes.
%HOMEPATH%\AppData\Local\Continuum\anaconda3\python.exe ^
%HOMEPATH%\AppData\Local\Continuum\anaconda3\cwp.py ^
%HOMEPATH%\AppData\Local\Continuum\anaconda3 ^
%HOMEPATH%\AppData\Local\Continuum\anaconda3\python.exe ^
%HOMEPATH%\AppData\Local\Continuum\anaconda3\Scripts\jupyter-lab-script.py
If you need to execute python scripts on Anaconda with the conveniance of running a BAT file, the above BAT file example should do the trick.
The data manipulation capabilities of pandas are built on top of the numpy library. In a way, numpy is a dependency of the pandas library. If you want to use pandas, you have to make sure you also have numpy. When you install pandas using pip, it automatically installs numpy. If it doesn't, try the following
pip install -U numpy pandas
For conda
conda install numpy pandas
I also faced the same issue. It happened to me after I upgraded my numpy library.
It was resolved in my case by upgrading my pandas library as well after upgrading my numpy library using the below command:
pip install --upgrade pandas
Try:
sudo apt-get install libatlas-base-dev
It should work now.
Else, try uninstall and reinstall numpy and pandas.
I had the same issue. It was because I had multiple versions of numpy installed. Remove all versions by repeatedly using:
pip uninstall numpy
Then re-install it with the command:
pip install numpy
First, try to import numpy on it's own, like so:
import numpy as np
I got this message:
ImportError: Something is wrong with the numpy installation. While importing
we detected an older version of numpy in
['/home/michael/.local/lib/python3.6/site-packages/numpy']. One method of
fixing this is to repeatedly uninstall numpy until none is found, then
reinstall this version.
So do what it says, keep uninstalling numpy until there is none, and then reinstall.
This worked for me.
I had the same issue while using Microsoft Visual Code with Python 3.7.3 64-bit('base':conda)as my python interpreter. Before running any code type the following three commands:
C:/ProgramData/Anaconda3/Scripts/activate #activate conda Scripts directory
conda activate base #activate conda
& C:/ProgramData/Anaconda3/python.exe #to run python
I have same problem.
I have got two version of numpy 1.16.6 and 1.15.4, fresh installed pandas did not work correctly.
I fixed it by uninstalling all versions of numpy and pandas and install the last versions.
$ pip uninstall numpy pandas -y
Uninstalling numpy-1.16.6:
Successfully uninstalled numpy-1.16.6
Uninstalling pandas-0.24.2:
Successfully uninstalled pandas-0.24.2
$ pip uninstall numpy pandas -y
Uninstalling numpy-1.15.4:
Successfully uninstalled numpy-1.15.4
Cannot uninstall requirement pandas, not installed
$ pip uninstall numpy pandas -y
Cannot uninstall requirement numpy, not installed
$ pip install numpy pandas
I had the same issue with anaconda package, it got updated.
anaconda {4.3.1 -> custom} ## I am not sure if this was the issue
Hit below command to know
conda list --revisions
what i did is just uninstall pandas with conda and re-install it
conda install pandas
Some new libs may also get installed with it.
It worked for me hope will do the same for you.
Uninstall all pip packages that you're having problems with. Manually remove all site-packages files. If you're using MacPorts, sudo port clean .
Then try reinstalling. Sometimes, there are files that should have been removed, but weren't if the installation was abruptly interrupted or something.
There could be an issue with conflicting versions of the package(s), as well as potentially issues with Pathing. Are you sure you've set the correct Path for your binaries? (/opt/local/bin, /anaconda2/bin, etc.)
Another issue could be some PYTHONPATH that's explicitly looking in the wrong place for the file.
I had a same issue recently with Anaconda with Python 3.7.
I solved this problem by downgrading python version to 3.6:
conda install python=3.6
and then by updating all the packages:
conda update --all
pandas is built on top of numpy so you need to have numpy to use the data manipulation feature, so install numpy first.
pip install numpy
This worked in my anaconda environment, but I do not know why conda does not work. For some reason conda uninstall was not sufficient. This only worked with conda remove.
conda remove pandas
conda remove numpy
conda install pip
pip install pandas
*With help from this answer
This raises the following import warning in python 3.6 and 3.7:
ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
If you with to ignore this warning (and maybe other ImportWarnings), add the following to your script before importing pandas:
import warnings
warnings.filterwarnings('ignore', category=ImportWarning, module='_bootstrap.py')
In my case even though I was using the above options of uninstall and installing using pip the code was still giving me same errors.
Finally, I created a vritual environment and Installed numpy and pandas using pip in my virtual env. Now the code is running.
Steps: for Anaconda3 - Please change according to your installation type:
[if you dont have virtual env package installed]
$ pip install virtualenv
[from command prompt go to the directory by c:\anadonda3\scripts
[write the following command to use virtual env to create a virtual env for you in your desired location]
$virtualenv c:\anaconda3\envs\my_virtual_env
[once created you will have to activate your virtual env]
$c:\anaconda3\envs\my_virtual_env\scripts activate
[now pip install numpy and pandas and other required packages using pip]
[once installations are done exit from the virtual env]
$c:\anaconda3\envs\my_virtual_env\scripts deactivate
now use the python.exe inside your virtual env folder to run the script and it will run even with python 3.7.
I am using Win10 and Conda, and this issue just append to me when upgrading python 3.7.2-h8c8aaf0_0 --> 3.7.2-h8c8aaf0_2.
I solved it by return to the previous version with
conda install python=3.7.2=h8c8aaf0_0
If you're running your program on PyCharm on Windows, there is a known bug, because PyCharm simply doesn't add env-related paths to PATH.
The issue is fixed in the 2019.1 Early Access Preview (EAP) build.
For me installing the EAP fixed the issue.
nothing worked for me ... except when I found this
I suspect that you have a local file called unittest.py that is getting imported instead of the standard module.
I was trying to upgrade my anaconda 2 with anaconda 3. I tried installing Anaconda3-2018.12-Windows-x86 and Anaconda3-2019.03-Windows-x86_64 on my Windows 10 machine and failed with this error. For me, using Anaconda3-4.4.0-Windows-x86_64 for anaconda 3 worked the trick after trying everything listed in answers here.
I fixed this using Anaconda by going to Environments > base(root), searching for numpy in the installed modules and clicking the tickbox alongside it and choosing > Mark for specific version installation > 1.14.0 (as suggested by another user on this thread). Then clicking Apply. Once it downgraded numpy I stopped getting errors when running py files on the command line.
Throughout this saga, I was still able to use https://pypi.org/project/auto-py-to-exe/ even when I was getting the numpy errors on the command line, but it was a hassle to create an exe every time I wanted to test a change. It's all sorted now. I guess there was a problem with numpy 1.16.4.
Anyway, I hope this helps someone who's using Anaconda as well.
The following worked for me.
Deleted the folders for numpy and pandas together with their contents completely from the site-packages folder. Check depending on whether you are using python2 or python3. Check the exact path as per your machine.
N.B handle with care "rm -rf" command. If you are not sure of what you are doing, please do it manually using any file explorer of your choice!!
rm -rf ~/anaconda2/envs/myenv/lib/pythonX/site-packages/pandas*
rm -rf ~/anaconda2/envs/myenv/lib/pythonX/site-packages/numpy*
Then i installed clean packages for pandas and numpy as usual with
pip install numpy
pip install pandas
I've got the same error recently. Before applying uninstall or install tools, try to update your Jupyter.
How? Go to 'Environments' and type on the Search Packages box 'pandas'. Afterwards, check the version (if that column shows a blue number with a diagonal arrow, it means that your pandas is out of date). Click on 'pandas' and a option will pop up (choose 'Apply' and wait for a couple of minutes to update the package). And then, make a quick test on any notebook to make sure that your Jupyter is running smoothly.
For those who couldn't solve with the above answers:
Ensure that you are running python3 with
$ python version
If not, install python3.
Then change default python to python3 with
$ alias python=python3
Next, close your jupyter lab/notebook environment and re-launch it with default python being python3.
build_exe_options = {"packages": ["os",'pandas','numpy']}
It works.
you are running python 3.7
create environment for python 3.6
python3.6 filename.py
I installed Jupyter notebooks in Ubuntu 14.04 via Anaconda earlier, and just now I installed TensorFlow. I would like TensorFlow to work regardless of whether I am working in a notebook or simply scripting. In my attempt to achieve this, I ended up installing TensorFlow twice, once using Anaconda, and once using pip. The Anaconda install works, but I need to preface any call to python with "source activate tensorflow". And the pip install works nicely, if start python the standard way (in the terminal) then tensorflow loads just fine.
My question is: how can I also have it work in the Jupyter notebooks?
This leads me to a more general question: it seems that my python kernel in Jupyter/Anaconda is separate from the python kernel (or environment? not sure about the terminology here) used system wide. It would be nice if these coincided, so that if I install a new python library, it becomes accessible to all the varied ways I have of running python.
Update
TensorFlow website supports five installations.
To my understanding, using Pip installation directly would be fine to import TensorFlow in Jupyter Notebook (as long as Jupyter Notebook was installed and there were no other issues) b/z it didn't create any virtual environments.
Using virtualenv install and conda install would need to install jupyter into the newly created TensorFlow environment to allow TensorFlow to work in Jupyter Notebook (see the following original post section for more details).
I believe docker install may require some port setup in the VirtualBox to make TensorFlow work in Jupyter Notebook (see this post).
For installing from sources, it also depends on which environment the source code is built and installed into. If it's installed into a freshly created virtual environment or an virtual environment which didn't have Jupyter Notebook installed, it would also need to install Jupyter Notebook into the virtual environment to use Tensorflow in Jupyter Notebook.
Original Post
To use tensorflow in Ipython and/or Jupyter(Ipython) Notebook, you'll need to install Ipython and Jupyter (after installing tensorflow) under the tensorflow activated environment.
Before install Ipython and Jupyter under tensorflow environment, if you do the following commands in terminal:
username$ source activate tensorflow
(tensorflow)username$ which ipython
(tensorflow)username$ /Users/username/anaconda/bin/ipython
(tensorflow)username$ which jupyter
(tensorflow)username$ /Users/username/anaconda/bin/jupyter
(tensorflow)username$ which python
(tensorflow)username$ /User/username//anaconda/envs/tensorflow/bin/python
This is telling you that when you open python from terminal, it is using the one installed in the "environments" where tensorflow is installed. Therefore you can actually import tensorflow successfully. However, if you are trying to run ipython and/or jupyter notebook, these are not installed under the "environments" equipped with tensorflow, hence it has to go back to use the regular environment which has no tensorflow module, hence you get an import error.
You can verify this by listing out the items under envs/tensorflow/bin directory:
(tensorflow) username$ ls /User/username/anaconda/envs/tensorflow/bin/
You will see that there are no "ipython" and/or "jupyer" listing out.
To use tensorflow with Ipython and/or Jupyter notebook, simply install them into the tensorflow environment:
(tensorflow) username$ conda install ipython
(tensorflow) username$ pip install jupyter #(use pip3 for python3)
After installing them, there should be a "jupyer" and a "ipython" show up in the envs/tensorflow/bin/ directory.
Notes:
Before trying to import tensorflow module in jupyter notebook, try close the notebook. And "source deactivate tensorflow" first, and then reactivate it ("source activate tensorflow") to make sure things are "on the same page". Then reopen the notebook and try import tensorflow. It should be import successfully (worked on mine at least).
i used these following which in virtualenv.
pip3 install --ignore-installed ipython
pip3 install --ignore-installed jupyter
This re-installs both ipython and jupyter notebook in my tensorflow virtual environment. You can verify it after installation by which ipython and which jupyter. The bin will be under the virtual env.
NOTE I am using python 3.*
I have another solution that you don't need to source activate tensorflow before using jupyter notebook every time.
Partion 1
Firstly, you should ensure you have installed jupyter in your virtualenv. If you have installed, you can skip this section (Use which jupyter to check). If you not, you could run source activate tensorflow, and then install jupyter in your virtualenv by conda install jupyter. (You can use pip too.)
Partion 2
1.From within your virtualenv, run
username$ source activate tensorflow
(tensorflow)username$ ipython kernelspec install-self --user
This will create a kernelspec for your virtualenv and tell you where it is:
(tensorflow)username$ [InstallNativeKernelSpec] Installed kernelspec pythonX in /home/username/.local/share/jupyter/kernels/pythonX
Where pythonX will match the version of Python in your virtualenv.
2.Copy the new kernelspec somewhere useful. Choose a kernel_name for your new kernel that is not python2 or python3 or one you've used before and then:
(tensorflow)username$ mkdir -p ~/.ipython/kernels
(tensorflow)username$ mv ~/.local/share/jupyter/kernels/pythonX ~/.ipython/kernels/<kernel_name>
3.If you want to change the name of the kernel that IPython shows you, you need to edit ~/.ipython/kernels/<kernel_name>/kernel.json and change the JSON key called display_name to be a name that you like.
4.You should now be able to see your kernel in the IPython notebook menu: Kernel -> Change kernel and be able so switch to it (you may need to refresh the page before it appears in the list). IPython will remember which kernel to use for that notebook from then on.
Reference.
Here is what I did to enable tensorflow in Anaconda -> Jupyter.
Install Tensorflow using the instructions provided at
Go to /Users/username/anaconda/env and ensure Tensorflow is installed
Open the Anaconda navigator and go to "Environments" (located in the left navigation)
Select "All" in teh first drop down and search for Tensorflow
If its not enabled, enabled it in the checkbox and confirm the process that follows.
Now open a new Jupyter notebook and tensorflow should work
Your Anaconda install probably went to different directory than your Python install
For instance on my machine I can find location here
yaroslavvb-macbookpro:~ yaroslavvb$ which ipython
/Users/yaroslavvb/anaconda/bin/ipython
When you type python, it tries to find it in PATH going in left-to-right order. So you may have another version of python in a folder before Anaconda folder, and it'll use that. To fix, you can do export PATH=.... to change the path, and put Anaconda directory in front, so that it takes python from there instead of the default, ie
export PATH=/Users/yaroslavvb/anaconda/bin:$PATH
I installed PIP with Conda conda install pip instead of apt-get install python-pip python-dev.
Then installed tensorflow
use Pip Installation:
# Ubuntu/Linux 64-bit, CPU only, Python 2.7
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7
# Requires CUDA toolkit 7.5 and CuDNN v4. For other versions, see "Install from sources" below.
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
...
pip install --upgrade $TF_BINARY_URL
Then it will work in jupyter notebook.
The accepted answer (by Zhongyu Kuang) has just helped me out. Here I've create an environment.yml file that enables me to make this conda / tensorflow installation process repeatable.
Step 1 - create a Conda environment.yml File
environment.yml looks like this:
name: hello-tensorflow
dependencies:
- python=3.6
- jupyter
- ipython
- pip:
- https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp36-cp36m-linux_x86_64.whl
Note:
Simply replace the name to whatever you want. (mine is hello-tensorflow)
Simply replace the python version to whatever you want. (mine is 3.6)
Simply replace the tensorflow pip install URL to whatever you want (mine is the Tensorflow URL where Python 3.6 with GPU support)
Step 2 - create the Conda environment
With the environment.yml being in the current path you are on, this command creates the environment hello-tensorflow (or whatever you have renamed it to):
conda env create -f environment.yml
Step 3: source activate
Activate the newly created environment:
source activate hello-tensorflow
Step 4 - which python / jupyter / ipython
which python...
(hello-tensorflow) $ which python
/home/johnny/anaconda3/envs/hello-tensorflow/bin/python
which jupyter...
(hello-tensorflow) $ which jupyter
/home/johnny/anaconda3/envs/hello-tensorflow/bin/jupyter
which ipython...
(hello-tensorflow) $ which ipython
/home/johnny/anaconda3/envs/hello-tensorflow/bin/ipython
Step 5
You should now be able to import tensorflow from python, jupyter (console / qtconsole / notebook, etc.) and ipython.
I think your question is very similar with the question post here. Windows 7 jupyter notebook executing tensorflow. As Yaroslav mentioned, you can try
conda install -c http://conda.anaconda.org/jjhelmus tensorflow .
I had a similar issue when using a custom Ubuntu 16 image. The problem was related to an existing version of numpy that was already installed on my system.
I initially tried
sudo pip3 install tensorflow
This resulted in the following exception:
Exception:
Traceback (most recent call last):
File "/anaconda/envs/py35/lib/python3.5/shutil.py", line 538, in move
os.rename(src, real_dst)
PermissionError: [Errno 13] Permission denied: '/anaconda/envs/py35/lib/python3.5/site-packages/numpy' -> '/tmp/pip-co73r3hm-uninstall/anaconda/envs/py35/lib/python3.5/site-packages/numpy'
The docs advise that if you encounter any issues with this command to try the following:
sudo pip3 install --upgrade \
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.1-cp35-cp35m-linux_x86_64.whl
However, my system was unable to locate pip3
sudo: pip3 command not found
The ulitmate solution was to create a symlink for pip3
sudo ln -s /anaconda/envs/py35/bin/pip3.5 /usr/local/bin/pip3
Finally, the following command worked without trouble
sudo /usr/local/bin/pip3 install --upgrade \
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.1-cp35-cp35m-linux_x86_64.whl
I verified the installation in the terminal and also verified a successful import in my Jupyter Notebook
import tensorflow as tf
I wonder if it is not enough to simply launch ipython from tensorflow environnement. That is
1) first activate tensorflow virtualenv with:
source ~/tensorflow/bin/activate
2) launch ipython under tensorflow environnement
(tensorflow)$ ipython notebook --ip=xxx.xxx.xxx.xxx
I found the solution from someone else's post. It is simple and works well!
http://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs
Just install the following in the Command Prompt and change kernel to Python 3 in Jupyter Notebook. It will import tensorflow successfully.
pip install tornado==4.5.3
pip install ipykernel==4.8.2
(Orginial post: https://github.com/tensorflow/tensorflow/issues/11851)
Jupyter Lab: ModuleNotFound tensorflow
For a future version of me or a colleague that runs into this issue:
conda install -c conda-forge jupyter jupyterlab keras tensorflow
Turns out jupyterlab is a plugin for jupyter.
So even if you are in an environment that has jupyter but not jupyterlab as well, if you try to run:
jupyter lab
then jupyter will look in the (base) environment for the jupyterlab plugin.
Then your imports in jupyter lab will be relative to that plugin and not your conda environment.
pip install tensorflow
This worked for me in my conda virtual environment.
I was trying to use conda install tensorflow in a conda virtual environment where jupyter notebooks was already installed, resulting in many conflicts and failure. But pip install worked fine.
conda info --envs
conda create --name py3-TF2.0 python=3
Proceed ([y]/n)? y
conda activate py3-TF2.0
conda install tensorflow
pip install --upgrade tensorflow
conda install -c anaconda ipykernel
python -m ipykernel install --user --name=py3-TF2.0
it is the best way but if it is required you should upgrade numpy with scipy as well
You can try "conda install tensorflow". This will install TensorFlow in your Anaconda directory.
Your local pip directory might not be shared with the Anaconda directory.
Thanks!
Open an Anaconda Prompt screen: (base) C:\Users\YOU>conda create -n tf tensorflow
After the environment is created type: conda activate tf
Prompt moves to (tf) environment, that is: (tf) C:\Users\YOU>
then install Jupyter Notebook in this (tf) environment:
conda install -c conda-forge jupyterlab - jupyter notebook
Still in (tf) environment, that is type
(tf) C:\Users\YOU>jupyter notebook
The notebook screen starts!!
A New notebook then can import tensorflow
FROM THEN ON
To open a session
click Anaconda prompt,
type conda activate tf
the prompt moves to tf environment
(tf) C:\Users\YOU>
then type (tf) C:\Users\YOU>jupyter notebook