I have ArcGIS Pro installed, which includes the installed Python packages. I am trying to learn Python and would like to use the ArcPy functions. I have never used Jupyter Notebook before, but to get started, I created a new Python 3 file. I entered the code to install arcpy but received an error.
pip install arcpy
ERROR: Could not find a version that satisfies the requirement arcpy (from versions: none)
ERROR: No matching distribution found for arcpy
import arcpy
ModuleNotFoundError: No module named 'arcpy'
I know I am missing a link somewhere, and I am guessing it has to do with environments. How can I reference the arcpy packages that are installed in my ArcGIS Pro program files?
Using "Non-ArcGIS Pro" Conda Environment
I assume that you use an Anaconda or Miniconda installation not provided by ArcGIS Pro, otherwise arcpy should already be available and there is no need to install it.
Note: If you want to use ArcGIS Pro's conda environment, scroll down to Using ArcGIS Pro's Conda Enviroment or Using Jupyter Notebook from within ArcGIS Pro.
To install arcpy, you need to use conda instead of pip. As far as I know arcpy is not available in the Python Package Index (pip's repository).
Initial Setup
Open Anaconda Prompt (or any command prompt if conda can be found through the PATH variable).
First you need a conda environment. Use the following command to create an environment called esri-notebook (can be any name):
conda create -n esri-notebook
Then activate the environment using:
conda activate esri-notebook
Install Jupyter Lab (or Notebook) with:
conda install jupyterlab
conda update --all
Install arcpy with:
conda install arcpy -c esri
Run Jupyter Lab with:
jupyter lab
Or, run Jupyter Notebook with:
jupyter notebook
Your browser will open with Jupyter Lab or Notebook.
Using Jupyter Lab/Notebook
Open Anaconda Prompt (or any command prompt if conda can be found through the PATH variable). Activate the environment:
conda activate esri-notebook
Run Jupyter Lab with:
jupyter lab
Or, run Jupyter Notebook with:
jupyter notebook
Your browser will open with Jupyter Lab or Notebook.
Using ArcGIS Pro's Conda Enviroment
Open Python Command Prompt. arcpy is available (no setup needed).
Then start Jupyter Notebook using:
jupyter notebook
Using Jupyter Notebook from within ArcGIS Pro
You can also create a notebook from within ArcGIS Pro and arcpy should be available to use it without any further setup. Find the Python button within the Analysis ribbon:
There are many questions like this (e.g. Conda environments not showing up in Jupyter Notebook, Python: modul not found after Anaconda installation, https://askubuntu.com/questions/1271137/importing-anaconda-libraries-not-working). I have tried their solutions but to no avail.
In short, I have conda installed. I have installed jupyterlabs and nb_conda_kernels in my base environment. When I create a new conda env via a file, the environment is not listed in jupyter automatically. I can add it via
python -m ipykernel install --user --name <env-name>
but then after I restart jupyter and switch kernels, when I try to import a python module from it, it says module not found.
What do I need to do to fix this? I do not want to add jupyterlabs to every env.
NOTE:
when activating the env in the terminal the path is correct, e.g. /opt/anaconda/anaconda3/envs/<env-name>/bin
when using the env in the terminal, the pack is there.
when using the kernel in Jupyter, the module is not there.
I have recently installed Spyder 2 on my MacBook. Then, since I couldn't import the sklearn library, i decided to also download Anaconda from their Website. Now, Anaconda comes with a Spyder environment itself, on which I can import sklearn, however the IDE is laggy. Is there a way to use the conda sklearn library on my separately downloaded Spyder (which runs much smoother)? Both Spyders are running Python 3.9.5 and I'm using MacOs 10.15.7
I tried setting a path via the PYTHONPATH Manager, but Spyder 2 forbids setting a path to 'site-packages' and after copying sklearn into another folder and setting a path there, import failed:
ModuleNotFoundError: No module named 'joblib'
I also installed sklearn via pip on the terminal, but I run into the same kind of problems if I try to import sklearn in my seperate Spyder 2('no module named sklearn found' or I can't set a path there or some module is missing).
And if I try to run
pip install scikit-learn
in the IPython console directly, I get
/Applications/Spyder 2.app/Contents/MacOS/python: No module named pip
while if I try
conda install scikit-learn
in the IPython console I get
ValueError: The python kernel does not appear to be a conda environment. Please use ``%pip install`` instead.
So I seem to be running in circles...
conda and pip are executables and not to be run from the IPython console, but from a command shell.
Don't mix conda and pip installations if you don't have to. Only install scikit-learn with conda.
Before you can use any installation, you have to activate the base environment first with conda activate.
There is no shame in reading the documentation first, e.g. https://docs.anaconda.com/anaconda/user-guide/getting-started/
I have made two new environments using conda and installed different dependencies in both environment. After activating one environment and opening jupyter notebook in that environment , I tried to import dependencies that I have installed for that environment but it showed me an error that this module is not present, after this I installed a jupyter notebook separately in that environment using :
pip install jupyter notebook
and error removed this time in that jupyter notebook. Also when I imported matplotlib in base environment it was imported but in new env it was showing no module error. Does it mean that whenever I have more than one environment , I have to install new jupyter notebook in every environment ?
I don't want to use other environment dependencies in current environment but all i am asking is why i am unable to import package in jupyter notebook even though i have installed them in this environment.
Please help me out for this issue. I have wasted my 10 to 15 days understanding this but I didn't find anything.
Please do the following steps:
source activate [your_env_name]
conda install ipykernel
ipython kernel install --name [your_env_name]
Once this is done, launch your python code from your Jupyter Notebook
Select Kernel -> Change Kernel -> [your_env_name]
I have installed Tensorflow and Keras by Anaconda (on Windows 10), I have created an environment where I am using Python 3.5.2 (the original one in Anaconda was Python 3.6).
When I try to execute import keras as ks, I get ModuleNotFoundError: No module named 'keras'.
I have tried to solve this issue by sys.path.append(C:\\Users\\ ... \\Anaconda3\\python.exe)
with both notebook and console, but I continue to get the same error.
How could I solve this issue?
Please try the following:
Run these in the jupyter notebook cell:
import sys
sys.path
sys.executable
It may not be pointing to your virtual environment but to the root
The fix is to install the jupyter notebook from inside your virtual environment
$ . your_env/bin/activate
(your_env)$ python -m pip install jupyter
Now you can import tensorflow or keras
Jupyter uses iPython under the hood, for python. So when you install Jupyter, it will also install iPython. There was one issue when I installed keras and Jupyter: I already have iPython installed in my root Anaconda environment. This is the output after I install Jupyter and keras:
In [2]: import sys; sys.path
Out[2]:
['/home/user/anaconda3/bin',
'/home/user/anaconda3/lib/python36.zip',
'/home/user/anaconda3/lib/python3.6',
'/home/user/.ipython']
Notice that even though I am inside my conda environment, it still looks for libraries in my root conda environment. And of course keras isn't there.
The step to fix is simply re-activate my environment, with:
source deactivate && source activate [my_env]
Then I am using a correct ipython:
Out[2]:
['/home/user/anaconda3/envs/ml3/bin',
'/home/user/anaconda3/envs/ml3/lib/python36.zip',
'/home/user/anaconda3/envs/ml3/lib/python3.6',
'/home/user/.ipython']
(Not an answer but some troubleshooting hints)
sys.path is not the path to your Python executable, but the path to the libraries.
Check where Keras is installed and check your sys.path. How exactly did you install Keras?
Try to execute the same command from the Python interpreter. Do you have the same issue?
How did you install Jupiter, is the sys.path visible from there the same as sys.path visible from your Python interpreter?
Do Jupiter and Keras use the same version of Python?
You might try to uninstall Jupiter and install it again, and hope that the new installation picks up the packages which are already installed. What could happen is that you have more than one Python installation and different libraries being installed to the different places. sys.path, when requested from different environments, might give you a hint if that's true.
The kernel in console and jupyter are not necessarily the same, and the problem might be that you are not on python 3.5.
python --version
should tell you what is running in the console, and in jupyter you should see it as a choice on starting a new notebook. For me, the information in
Using both Python 2.x and Python 3.x in IPython Notebook
was very helpful.
I have realized that I had two different Jupyter's directories, so I have manually deleted one on them. Finally, I have reinstalled Anaconda. Now Keras works properly.
If you are a windows/mac user who are working on Jupyter notebook “pip install keras” doesn't help you .Try the below steps.It was solved for me
1. In command prompt navigate to the “site packages” directory of your anaconda installed.
2. Now use “conda install tensorflow” and after “conda install keras”
3. Re-start your Jupyter notebook and run the packages.
Acually, I did this command pip install keras and sudo -H pip3 install keras and pip3 install keras. None of them worked. I added the following command and everything worked like a charm:
pip install Keras. Yes a capital 'K'
Here's how I solved this problem.
First, the diagnosis. When I run which python in a terminal window on my Mac (the same terminal I used to launch jupyter, I get /Users/myusername/.conda/envs/myenvname/bin/python, but when I run the same command from a terminal within Jupyter, I get /usr/bin/python. So Jupyter isn't using the correct python executable; the version it's using doesn't have any of my packages installed.
But which jupyter returns /usr/bin/jupyter; it's using a version of jupyter that isn't coming from within my conda environment. I ran conda install jupyter and now which jupyter returns /Users/myusername/.conda/envs/myenvname/bin/jupyter (for some reason I had to restart the terminal window for this to take effect.) Then if I relaunch jupyter notebook, the notebook is using the correct version of Python and I have access to all my installed conda packages. 👍
I had a similar problem.
I added the Conda environment as a new kernel.
First, install ipykernel:
conda install ipykernel
Next, create the kernet:
python -m ipykernel install --user --name tf-gpu --display-name "TensorFlow-GPU"
Now, when you run your notebook, change the kernel to the new one, to "TensorFlow-GPU" in this example.