Installation:
I'm a newbie in Python and I'm facing issues with Anaconda. Whenever I launch Anaconda Navigator it shows Python stopped working and crashes.
Also if I type python in the command prompt I get a warning:
"Python interpreter is in a conda environment, but the environment has not been activated. Libraries may fail to load. To activate this environment please see https://conda.io/activation"
I have seen such questions before and tried the solutions, but nothing seems to work. I also tried to reinstall, but it's the same every time.
Try:
conda activate base
Or create a venv:
conda create my_env
conda activate my_env
Or install the Python system directly. Download from here.
This seems to be two separate issues:
Crashing on Anaconda Navigator startup
Try to update PyQt. For more information, see: Spyder and Anaconda Navigator do not open - "Python has stopped working" (Fixed) #10088
For the Python commands, try to activate your environment: conda activate base.
I have been using Spyder installed with with Anaconda distribution which uses Python 2.7 as default. Currently I need to set up a development virtual environment with Python 3.4.
Top two suggestions after research online are:
to set up virtual environment first and to point change the preferences of Spyder , e.g here;
to install all Spyder dependencies, like PyQt4, in the virtual environment itself, e. g. here ;
Both recommendations are cumbersome and do not look like smart options for development.
Is there a solution that would allow to run Spyder with required Python version automatically after activating the required virtual environment?
Here is a quick way to do it in 2021 using the Anaconda Navigator. This is the most reliable way to do it, unless you want to create environments programmatically which I don't think is the case for most users:
Open Anaconda Navigator.
Click on Environments > Create and give a name to your environment. Be sure to change Python/R Kernel version if needed.
Go "Home" and click on "Install" under the Spyder box.
Click "Launch/Run"
There are still a few minor bugs when setting up your environment, most of them should be solved by restarting the Navigator.
If you find a bug, please help us posting it in the Anaconda Issues bug-tracker too! If you run into trouble creating the environment or if the environment was not correctly created you can double check what got installed: Clicking the "Environments" opens a management window showing installed packages. Search and select Spyder-related packages and then click on "Apply" to install them.
There is an option to create virtual environments in Anaconda with required Python version.
conda create -n myenv python=3.4
To activate it :
source activate myenv # (in linux, you can use . as a shortcut for "source")
activate myenv # (in windows - note that you should be in your c:\anaconda2 directory)
UPDATE. I have tested it with Ubuntu 18.04. Now you have to install spyder additionally for the new environment with this command (after the activation of the environment with the command above):
conda install spyder
(I have also tested the installation with pip, but for Python 3.4 or older versions, it breaks with the library dependencies error that requires manual installation.)
And now to run Spyder with Python 3.4 just type:
spyder
EDIT from a reader:
For a normal opening, use "Anaconda Prompt" > activate myenv > spyder (then the "Anaconda Prompt" must stay open, you cannot use it for other commands, and a force-close will shut down Spyder). This is of course faster than the long load of "Anaconda Navigator" > switch environment > launch Spyder (#adelriosantiago's answer).
What worked for me :
run spyder from the environment (after source activate)
go to Tools --> preferences --> python Interpreter and select the python file from the env you want to link to spyder
ex : /home/you/anaconda3/envs/your_env/bin/python
Worked on ubuntu 16, spyder3, python3.6.
Additional to tomaskazemekas's answer: you should install spyder in that virtual environment by:
conda install -n myenv spyder
(on Windows, for Linux or MacOS, you can search for similar commands)
To do without reinstalling spyder in all environments follow official reference here.
In summary (tested with conda):
Spyder should be installed in the base environment
From the system prompt:
Create an new environment. Note that depending on how you create it (conda, virtualenv) the environment folder will be located at different place on your system)
Activate the environment (e.g., conda activate [yourEnvName])
Install spyder-kernels inside the environment (e.g., conda install spyder-kernels)
Find and copy the path for the python executable inside the environment. Finding this path can be done using from the prompt this command python -c "import sys; print(sys.executable)"
Deactivate the environment (i.e., return to base conda deactivate)
run spyder (spyder3)
Finally in spyder Tool menu go to
Preferences > Python Interpreter > Use the following interpreter and paste the environment python executable path
Restart the ipython console
PS: in spyder you should see at the bottom something like this
Voila
I just had the same problem trying to get Spyder to run in Virtual Environment.
The solution is simple:
Activate your virtual environment.
Then pip install Spyder and its dependencies (PyQt5) in your virtual environment.
Then launch Spyder3 from your virtual environment CLI.
It works fine for me now.
The above answers are correct but I calling spyder within my virtualenv would still use my PATH to look up the version of spyder in my default anaconda env. I found this answer which gave the following workaround:
source activate my_env # activate your target env with spyder installed
conda info -e # look up the directory of your conda env
find /path/to/my/env -name spyder # search for the spyder executable in your env
/path/to/my/env/then/to/spyder # run that executable directly
I chose this over modifying PATH or adding a link to the executable at a higher priority in PATH since I felt this was less likely to break other programs. However, I did add an alias to the executable in ~/.bash_aliases.
From Spyder official page on Github:
The naive approach
To use Spyder with another environment, the simplest way is to just
install it directly into the environment from which you'd like to use
the packages in, and run it from there. This works with all Spyder
versions and should require no extra configuration once the IDE is
installed; however, it results in multiple installations to manage and
isn't as flexible or configurable as the alternative. Therefore, when
dealing with multiple environments, we recommend the modular
approach.
The modular approach
Starting with Spyder 3.3.1, you can install the modular
spyder-kernels package into any Python environment (conda
environment, virtualenv/venv, system Python, WinPython, etc) in
which you wish to work, and then change the Python interpreter used by
Spyder on its IPython consoles to point to the Python executable of
that environment.
This takes a small amount of preparation and configuration, but is
much "lighter" and quicker than a full Spyder installation into that
environment, avoids dependency conflicts, and opens up new workflow
possibilities.
To achieve this, follow these steps:
1- Activate the environment (e.g. myenv) in which you'd like to work (e.g. with conda activate myenv for conda, source myenv/bin/activate or workon myenv for virtualenv/venv, etc)
2- Install the spyder-kernels package there, with the command:
3- conda install spyder-kernels if using conda/Anaconda,
4- pip install spyder-kernels if using pip/virtualenv.
5- After installing via either method, run the following command inside the same environment:
python -c "import sys; print(sys.executable)"
and copy the path returned by that command (it should end in
python, pythonw, python.exe or pythonw.exe, depending on your
operating system).
6- Deactivate that environment, activate the one in which Spyder is installed (if you've installed it in its own environment) and start
Spyder as you normally would.
7- After Spyder has started, navigate to Preferences > Python Interpreter > Use the following interpreter and paste the path from
Step 3 into the text box.
8- Start a new IPython console. All packages installed in your myenv environment should be available there. If conda is used, the
name of the current environment and its Python version should be
displayed in Spyder's status bar, and hovering over it should display
the path of the selected interpreter.
On Windows:
You can create a shortcut executing
Anaconda3\pythonw.exe Anaconda3\cwp.py Anaconda3\envs\<your_env> Anaconda3\envs\<your env>\pythonw.exe Anaconda3\envs\<your_env>\Scripts\spyder-script.py
However, if you started spyder from your venv inside Anaconda shell, it creates this shortcut for you automatically in the Windows menu. The steps:
install spyder in your venv using the methods mentioned in the other answers here.
(in anaconda:) activate testenv; though in my case, this step was not needed.
Look up the windows menu "recently added" or just search for "spyder" in the windows menu, find spyder (testenv) and
[add that to taskbar] and / or
[look up the file source location] and copy that to your desktop, e.g. from C:\Users\USER\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit), where the spyder links for any of my environments can be found.
Now you can directly start spyder from a shortcut without the need to open anaconda prompt.
For me below worked:
Open Anaconda, setup new environment, then select the env and click on play icon as shown below:
Then click on Open Terminal, and type "spyder" in terminal, it will open the spyder with selected env.
Note: For me directly opening Sypder from Home page was always opening with base env.
I follow one of the advice above and indeed it works. In summary while you download Anaconda on Ubuntu using the advice given above can help you to 'create' environments. The default when you download Spyder in my case is: (base) smith#ubuntu ~$. After you create the environment, i.e. fenics and activate it with $ conda activate fenics the prompt change to (fenics) smith#ubuntu ~$. Then you launch Spyder from this prompt, i.e $ spyder and your system open the Spyder IDE, and you can write fenics code on it. Remember every time you open a terminal your system open the default prompt. You have to activate your environment where your package is and the prompt change to it i.e. (fenics).
I am having difficulty with creating a new conda (Anaconda 3, python 3.7) environment using Pycharm (edition 2019.2.2.)
I have added the (hopefully) correct Conda.exe file (from Users\...\AppData\Local\Continuum\anaconda3\Scripts\conda.exe) as Conda executable, but the installer does not install the first package (pip-19.2.2) while creating the Conda environment.
Am I doing something wrong?
I have solved the problem with the help of Pycharms support team.
If you are also not able to create a conda environment in Pycharm, first try to run:
conda update python-libarchive-c
in the anaconda command prompt.
If this doesn't work and pycharm is still stuck while making a virtual environment, do the following:
Look into your log: in pycharm go to help -> show log in explorer.
For me PyCharm stumbled upon the following command:
C:\Users\\...\AppData\Local\Continuum\anaconda3\Scripts\conda.exe create -p C:\Users\\...\AppData\Local\Continuum\anaconda3\envs\Project_OpenPNM -y python=3.7
Try running this command directly in the anaconda prompt. Subsequently, activate your environment and add the python interpreter created directly as an excisting interpreter in pycharm.
I just installed PyCharm and Anaconda. I installed PyTorch to Anaconda and i can even use "import torch" in Anaconda. I've created a new Project in PyCharm with the Anaconda Interpreter but i still can't use PyTorch in PyCharm.
I had this problem also. Program that imported torch worked fine at anaconda prompt running in my pytorch env, but when i ran pycharm from the windows shortcut and EVEN set my environment to use pytorch env, it would complain torch could not be imported.
When i ran pycharm from the prompt as shown, it worked.
If you used a bash script and the conda environment to run python codes in your PyCharm IDE.
You also need source activate myenv in your bash script.
Like this:
#!/usr/bin/env bash
source activate myenv
python test.py
source deactivate
I got the same problem and you that how i solved the problem:
1- when you open project choose conda as your project interpreter as shown here
2- in your project go to setting -> project: project name -> Project Interpreter check that you are using Conda Package Manager and your anaconda local settings
I got same problem and solved it:
After you installed anaconda, source activate your own envrionment.
Install pycharm-community and pytorch follow their official instructions.
Start pycharm-community in the same anaconda environment.
Loading your own project, followed instructions as Manuel Lagunas
Finally, you have to install packages of torch in the environment of pycharm: pictures as:
press '+' on the right side to install
you can choose packages of torch by typing 'torch'
Finally solved this in Windows 10 after sinking an entire morning into it.
Create a new Conda environment (via PyCharm or however you fancy)
Navigate to C:\Your\Environment\Path\Scripts in a command terminal
Mine looks like this: C:\ProgramData\Anaconda3\envs\Snek_V2\Scripts
Find what commands you would need for a pip install from the PyTorch website
They'll look something like this:
pip3 install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp37-cp37m-win_amd64.whl
pip3 install torchvision
In the command terminal, you want to enter those commands with one difference; you'll need to replace pip3 with pip.exe. As you've navigated to the exact environment you plan to work in, this will be the pip relevant to you.
e.g. pip.exe install torchvision
Open PyCharm and open the project that's working in the Conda environment we just set up.
If you open up a Python Console, you should now be able to enter import torch and not have any errors pop up in response.
I am configuring Anaconda 1.9.1 together with Python 3.3.4 and I am unable to setup Matplotlib for anaconda environment when I try to add package using Pycharm. I also tried to install from Matplotlib.exe file which I downloaded from its website. I can not change the installation directory in that case. I would like to know that is there a way to tackle this issue.
If you're using anaconda, your default environment is Python 2.7. You need to create a new environment and install matplotlib in there.
In a command prompt, do the following (saying yes to the questions):
conda create --name mpl33 python=3.3 matplotlib ipython-notebook
activate mpl33
ipython notebook
You should be able to import matplotlib when the notebook server comes up.
The first command simultaneously creates the environment and install
the listed packages.
The second command activates the new environment by prepending its location to the system path
The third command just starts the ipython notebook so that you can test out everything
I don't know how pycharm works, but my guess is that you'll have to tell it to look for the right python that you want to use. In this case it'll be something like: C:/Users//anaconda/envs/mpl33. In any case, the command prompt should display the path when you activate the environment.
Once you've activated your environment, you can install more packages like this:
conda install pandas=0.12
conda install pyodbc statsmodels
You can specific version numbers of packages like the first command or simply accept the latest available version (default)
Assuming you've already installed a 3.x python env in anaconda, this one line should do the trick:
conda install matplotlib -n name
where name is the name you previously gave to your python 3 anaconda env. If you're not sure of the name you gave it, it will be the name of a subdir in the Anaconda\envs directory.
Background: I recently went through the same trouble with matplotlib not getting installed by default by anaconda when I added a full python 3 env, even though it's meant to. The above line solved it for me; it gave me the following warnings so it seems likely that the two different available versions caused it to initially install neither. However it allowed me to choose the one I wanted, and then everything worked great.
Warning: 2 possible package resolutions:
[u'dateutil-2.1-py33_2.tar.bz2', u'matplotlib-1.3.1-np18py33_1.tar.bz2', u'numpy-1.8.0-py33_0.tar.bz2', u'pyparsing-2.0.1-py33_0.tar.bz2', u'pyside-1.2.1-py33_0.tar.bz2', u'python-3.3.5-0.tar.bz2', u'pytz-2013b-py33_0.tar.bz2', u'six-1.6.1-py33_0.tar.bz2']
[u'dateutil-2.1-py33_2.tar.bz2', u'matplotlib-1.3.1-np17py33_1.tar.bz2', u'numpy-1.7.1-py33_3.tar.bz2', u'pyparsing-1.5.6-py33_0.tar.bz2', u'pyside-1.2.1-py33_0.tar.bz2', u'python-3.3.5-0.tar.bz2', u'pytz-2013b-py33_0.tar.bz2', u'six-1.6.1-py33_0.tar.bz2'
]
conda install -c conda-forge matplotlib