I am trying to work with Arcpy from Spyder, but when I import the Arcpy package, I receive the following message:
ModuleNotFoundError: No module named 'arcpy'
I tried to install Arcpy package 2.7 (my ArcMap and IDLE version) through Anaconda prompt:
conda install arcpy=2.7 -c esri
but I wasn't successful.
So far I've been working with IDLE, but what I really want is to work with arcpy directly from Spyder. Specially to extract vector and raster data (geometry coordinates, atribute table values, etc), so that I can work with it afterwards.
Is there any way of achieving that?
Thanks in advance.
You could try switching environments to the directory where your current python environment is located. For example, if you are using ArcGIS Pro your *.exe file is normally found here: C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3
https://docs.spyder-ide.org/current/faq.html#using-existing-environment
To work with an existing environment in Spyder, you need to change Spyder’s default Python interpreter. To do so, click the name of the current environment in the status bar, and then click Change default environment in Preferences.
This will open the Preferences dialog in the Python interpreter section. Here, select the option Use the following Python interpreter, and use the dropdown below to select your preferred environment. If its not listed, use the text box or the Select file button to enter the path to the Python interepreter you want to use. See the IPython Console for more information.
Click Restart kernel in the Consoles menu for this change to take effect.
Or you could install Anaconda, which comes with Spyder, and create a new environment. That way you could start fresh and install whatever packages you like, including arcpy. conda install -c esri arcgis
This cheat-sheet is handy once you've installed Anaconda.
https://docs.anaconda.com/anaconda/install/
Edit:
Since you're still using ArcMap v.??? try pointing to your python environment that comes with the ArcMap installation from the Spyder Preferences menu. Sorry, I've moved on from ArcMap and Python 2.x years ago (wink).
https://desktop.arcgis.com/en/arcmap/latest/analyze/python/importing-arcpy.htm#ESRI_SECTION1_5E64CCAB40C24B0DB1ED80EF96176F73
ArcGis Pro with Python 3.x have Anaconda and Spyder installed. Older ArcGis Desktop with python 2.x Do not have Anaconda/Spyder installed. I think it's impossible to install ArcPy as library. It's only working within python environment delivered with ArcGIS.
Related
I have noticed this both on Linux and MacOS. I have a conda environment for data science stuff, which I have installed ipython, ipykernel, jupyer, and a bunch of other data science dependencies. In VSCode, when I try to select a python interpreter, it shows just fine.
I have been able to run regular python files without issue. However, in Jupyter notebooks, when I try to select a kernel, it is only showing the system installed python interpreter (/usr/bin/python and such). Oddly, sometimes if I click the 'Select kernel' button early enough, it will temporarily show the conda environment as an option, but then in a second it will disappear. If I click the option fast enough, it also just resets to the system python and when I try again to select the kernel, it only shows the system options.
This problem occurs in python 3.11.
Open the extension store and change the jupyter extension to pre-release version.
Use command python -m pip install jupyter in the terminal.
Use shortcuts "Ctrl+Shift+P" and search the following option:
I downloaded the student version of Pycharm from https://www.jetbrains.com/de-de/community/education/#students.
We use Anaconda and Open CV as a package manager and basic library.
I have a problem with the interpreter. I open a new project and select "Pure Python" and under the bar "new environment using Virtualenv". The paths for location and base interpreter were already entered:
When I next click on "Create" an error message appears, which says "Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640":
And when I write a program and click "run" the same message appears.
The same problem was described in the English forums. The path of the executable could be important if I got that right. The executable is saved under AppData \ Local \ Microsoft \ WindowsApps. I can't move that either. I did everything as my professor did before, only for him the executable was not saved under "Windows Apps" but normally under Programs \ Python \ Python.exe.
If you are using anaconda, then choose "conda" as the environment type instead of "virtualenv". You can also choose an existing interpreter if you already create the environment in conda (or if you want to use the base environment that is already created when you install anaconda).
You are trying to create a virtual environment using AppData\Local\Microsoft\WindowsApps\python.exe as a base interpreter but it is not a real Python interpreter it is a some sort of a Windows specific shortcut which suggests to install Python from Windows store.
If I recall correctly modern PyCharm is smart enough not to suggest this "fake" interpreter as a base for a virtual environment so make sure you are using the latest IDE version available.
We use Anaconda and Open CV as a package manager and basic library
If you have Anaconda installed - select it from existing interpreters
... or create a conda environment as darcamo suggests.
only for him the executable was not saved under "Windows Apps" but normally under Programs \ Python \ Python.exe
Your professor is using Python installed from python.org, which you can also install if you don't want to use conda. 3.8.6 should be a decent choice.
i have attached ss for creating conda enviroment.
make sure that your giving correct path of conda.exe
its present in H:\anaconda\Scripts\conda.exe your anaconda installed directory.
I have a VM running only Anaconda. There are no other available installations of Python. This is all I see when I run "Apps and Features" in Windows 10 and filter for Python (note that it is Python 3.7.4):
When I go to the Conda prompt and enter conda list, I see that I have openCV installed :
but it's with a version of Python 3.7.6:
However when I open VS Code and I set my Python Path to the version in the Anaconda folder: (C:\Users\Me\Anaconda3\Python.exe) and try to import OpenCV, I get the "module not found" error. When I create a new python file and run
help("modules")
I do not see OpenCV in the list below in the terminal even though its installed.
Any idea how this is happening? I just don't see a second installation of Python on my PC, but why am I seeing 3.7.4 and 3.7.6 and is this possibly causing my issue?
Edit: Added a picture of the error I get when trying to run it.
Install anaconda plugin in VSCode and select your conda environment in the bottom left of VSCode window.
If you didn't create a conda environment, the you will probably have installed the package in the base environment.
Edit: Reading the PyPi project, I found the right way to import opencv in python code.
import cv2
I'm using VSCode for python programming. The interpreters are from Anaconda (Python 3.7 in the latest version of Anaconda). I've added the Anaconda folder path into the system environment variables:
I've installed packages numpy and numba via conda, and I created an environment which contains those packages:
And the current VSCode is working under that environment:
It works fine in PyCharm by using the same interpreter/environment, but
when I switched to VSCode it always gets me error: ImportError: No module named numba. I don't know how to fix that.
You don’t have to manually add environment in VS Code. Remove all the path you have manually added. Bring up the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of VS Code or the View: Extensions command (⇧⌘X (Windows, Linux Ctrl+Shift+X)).
Search for Anaconda extension. Install and refresh your VS Code. Open your project folder and click on of your .py file. VS Code will search all available Pythons in your system.
On the bottom right you should be able to select a correct environments
I have Conda and Spyder installed for Python 3x, but need to write a script in 2x.
Is it possible to do this without reinstalling Conda for 2x?
When you open the Anaconda Launcher app, in the bar at the top there is a drop down menu for environment. Click on this menu, choose new environment, and choose Python 2.x as the Python version. Note that you will have to install a second copy of spyder from inside the Launcher, but you won't have to reinstall the whole stack.
edit: see this to install a new environment without the GUI launcher: http://conda.pydata.org/docs/py2or3.html
2nd edit to clarify comment below: All packages that are installed by default by Anaconda should be available to whichever python environment you set up through Anaconda. To see which packages are available to you, enter
help('modules')
into your python console.