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.
Related
I'm using Pop_OS! Linux. Whenever I make a Python Virtual Environment using mkvirtualenv and then pip install packages into it, that environment does not work when I reference it inside pycharm. I set up virtual environments using virtualenv and virtualenvwrapper.
The workaround I've found is to build any virtual environment you need to use inside of PyCharm inside of pycharm, or using the terminal inside of PyCharm. I'm annoyed it doesn't seem compatible with my native terminal, and can't figure out why. I even get slightly different python versions by running python --version both inside the PyCharm terminal and in the native linux terminal, while inside the same virtual environment! It's like Pycharm isn't reading the same information out of the python environment directory as my terminal is.
What is going on here, and how do I harmonize PyCharm with the rest of my linux machine? I'm also new to Pop_OS! Trying it out for the first time is an adventure.
IDK if that will work, but maybe if you install your packages via the "Python packages" tab in PyCharm (down left -> add package next to the research bar that appeared), PyCharm will see them while it installed them itself.
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.
In general I am new to python so keep it easy. I have started my coding in Spyder since it was easy to install libraries with Anaconda.
Now we want to switch to VS Code for version control. I have switched interpreter and python path to Anaconda folder, but if I open python files I have created in Spyder I can't use in VS code, issue always is with importing libraries.
Screenshot
The first rule with Anaconda is to not manually mess around with the paths. Anaconda has a different philosophy: Before you can use Python, you need to activate a conda environment.
c:\> conda activate
(Anaconda3) c:\> python
>>>
VSCode detects conda environments and you just have to select one for your project (Python: Select interpreter). Now open a new terminal and watch VSCode activating the environment for you (like shown above).
However, when you start your script for the first time, VSCode sometimes invokes the interpreter even before the conda activation has finialized. Then simply restart your script.
Consider:
My PyCharm installation was running Python 2. I downloaded Python 3.7 and installed it. It's able to work in PyCharm when I first time run it, however, when I reopen the file and try to run it, it shows warning message:
Invalid Python interpreter selected
And when I try to switch it into 3.7, the choice is shown in red and says invalid.
PyCharm with Python > 3.3 is using venv (virtual environment) to allow per project Python modules. You need to create a new valid venv (as described in kimbaudi's comment):
Click the gear icon next to the Project Interpreter: dropdown and
select Add.... Select Virtualenv Environment and select either a New
Environment or Existing Environment
If you want to use your preinstalled system modules, you need to check Inherit global site-packages or otherwise you need to reinstall the modules you want to use in the venv. Also see configure a virtual environment.
I have an Anaconda (not miniconda) Python 2.7 install on Windows. I would like to update the version of Python installed to the latest minor version (2.7.9), which I see is available in the channels that conda is configured to use. However, typing conda update python basically says:
# All requested packages already installed.
# packages in environment at C:\Anaconda:
#
python 2.7.5 2
How does one update to another minor version of Python on Windows? I guess that since conda is written in Python and Windows does not let you overwrite or delete open files, that might be slightly difficult to do on Windows... But is it possible?
You are right that Windows won't let conda update Python in the root environment. The only option is to create a new environment with conda create. Otherwise, for now, you will have to reinstall Anaconda to update the root environment Python. We are working on a way to update Python in the root environment, but it isn't finished yet.