modified PYTHONPATH not recognized by Anaconda Spyder - anaconda

I use my .bash_profile to add a directory to PYTHONPATH
export PYTHONPATH="${PYTHONPATH}:/Users/selah/newdir"
In my Anaconda installation of Spyder the path I added does not show up when I type:
import sys
sys.paths
However when i do the same in Jupyter notebook, or terminal python it does show up.
Why the discrepancy? Is there a way to get Spyder to recognize my modified PYTHONPATH?

(Spyder developer here) You need to start Spyder from the command line for your changes to be detected by Spyder.
This is because Spyder doesn't have a way to read your environment variables when started in a graphical way.

I had a similar problem. For future reference, resolved by adding path under menu “python > PYTHONPATH manager” option.

Related

How to import geopandas in Pycharm if installed using conda? [duplicate]

Conda env is activated using source activate env_name.
How can I activate the environment in pycharm ?
open
pycharm/preferences/project/Project Interpreter
And check existing interpreter. Conda environments may already be listed there.
If not exists, you can create a new conda environment with "Create Conda Env" button
If you are looking for a specific conda environment you can use 'add local'. When you click 'add local' you will input conda environment path + /bin/python
You can list all conda environment in your system with following commnad.
>>conda info --env
# conda environments:
#
tensorflow * /Users/username/miniconda3/envs/tensorflow
you can chose the approach best fits your needs.
The best PyCharm specific answer is this one by wasabi (below).
In general though, if you want to use an interpreter from within a Conda environment then you can change the location of the interpreter to point to the particular environment that you want to use e.g. /home/username/miniconda/envs/bunnies as mentioned in this comment.
However, as mentioned in this answer by Mark Turner, it is possible to have a shell script executed when activating an environment. This method will not run that shell script, but you can follow his workaround if you need that shell script run:
open a conda prompt
activate the environment
run pycharm from the conda prompt
How about environment.yml
Pycharm can create a new conda environment indeed. Unfortunately, until this issue is fixed, it won't offer environment.yml support, which means it won't install the dependencies declared there.
When working on a project based on such a file, you need to create / update the dedicated env manually on your machine:
conda env create -n <my-project>
Then remember to update each time environment.yml changes (from you or upstream).
conda env update -n <my-project>
Not ideal
As mentioned in one of the comments above, activating an environment can run scripts that perform other actions such as setting environment variables. I have worked in one environment that did this. What worked in this scenario was to:
open a conda prompt
activate the environment
run pycharm from the conda prompt
Pycharm then had access to the environment variables that were set by activating the environment.
I had the same problem i am on windows 10 professional 64 bit
my solution was to start Pycharm as adminstrator and it worked
Go to settings at the top right corner of the PyCharm IDE.
Go to Project:{Your Project Name}->Python Interpreter
Go to the settings inside here and click add:
In Add Python Interpreter select conda env
Select existing environment and click on your required conda environment path from the dropdown menu OR add the path of the python.exe file in your conda environment. As a reference, I am adding the path for my windows10 system: C:\Users\maria\AppData\Local\Continuum\anaconda3\envs<mycondaenv>\python.exe It can vary for your system based on installation configs.
It seems important to me to know, that setting project interpreter as described in wasabi's comment does not actually activate the conda environment.
I had issue with running xgboost (that I installed with conda) inside PyCharm and it turned out that it also need some folders added to PATH. In the end I had to make do with an ugly workaround:
Find out what are the additional folders in PATH for given environment (with echo %PATH% in cmd)
In the file I wish to run put to the top before anything else:
import os
os.environ["PATH"] += os.pathsep + os.pathsep.join(my_extra_folders_list)
I know this is not at all proper solution, but i was unable to find any other beside what Mark Turner mentioned in his comment.
To use Conda environment as PyCharm interpreter
activate Conda environment from Conda navigator
open PyCharm from the navigator tool list
in Conda Add interpreter section choose existing Conda environment and it automatically recognises the path of that environment's python.exe file
First , select Interpreter setting ... in right bottom of Pycharm.
Then choose python.exe from your desired conda environment.
My environment path is : C:\Users\javadsh\anaconda3\envs\tf-gpu\python.exe
Go to Pycharm -> Preferences -> Project Interpreter. At the top left of the packages table there is a plus sign, minus sign, a green circle and an eye; uncheck the green sign; that will let you have access to the packages while using conda environment.

I have added conda and python path to the environment variable, but jupyter notebook is still not getting opened from cmd

I was trying to add conda and python to the environment variable using SETX Command from CMD but it was failing. I tried setting it using PowerShell and it worked. The path was added successfully but I still can't open Jupyter Notebook from my cmd.
Adding Python to the environment path is bad practice, see Anaconda FAQ. If you haven't installed Anaconda with it's default settings, you first need to:
Initialize your shells
conda init --all
After this you should have ../Anaconda3/condabin only in your path (more information via conda init --help).
But before you can run Jupyter, you also need to activate Anaconda:
C:\> conda activate
(base) C:\> jupyter notebook
The activation will add the following folders of the conda base environment to your PATH:
\Anaconda3;
\Anaconda3\Library\mingw-w64\bin;
\Anaconda3\Library\usr\bin;
\Anaconda3\Library\bin;
\Anaconda3\Scripts;
\Anaconda3\bin;
The python.exe resides in Anaconda3, jupyter.exe in Anaconda3\Scripts, so it's not enough to just add the first folder to your Path. And it's especially important to have the libraries on your Path when you want to run C-based packages like numpy.
But the very point behind the conda activate mechanism is that it allows you to configure and run different environments with different versions of python and 3rd party packages that would otherwise conflict, see Managing environmnts.
On top of that you can even install Python from python.org next to your Anaconda distribution, since conda will make sure that they won't interfere.

How to use root anaconda environment in Pycharm

I am new to anaconda and pycharm. I wanted to ask that why can I use all root anaconda packages when I use spyder, but when I use pycharm I have to create a new environment and install all the packages again, which also take up alot of memory space. Can I not use the root env of anaconda in pycharm?
Here is a link that shows how to set the anaconda interpreter for pycharm. I recommand you to use environments because all the packages have dependencies that are difficult to reproduce and you can export and import your environment with yml files.

Anaconda Navigator create new enviorment and it doesn't show up

I just downloaded Anaconda and I'm using Navigator for the first time on Windows. I've been using Conda through the command line for awhile now, so I'm familiar with the concept of environments and how to use them. Right now, the only enviorment showing up in navigator is root. I want to install some additional packages, so I went ahead and cloned the root environment. This doesn't cause any errors, and seems to have worked, except I don't see my new environment.
I know the enviorments are successfully being created, as I can see them when I go through the Anaconda Prompt.
Any thoughts why this is not working?
The answer from this question : Anaconda Navigator does not show new environments
It goes like this:
1) Check that the new environment is there from conda prompt:
conda info --envs
2) update conda
conda update anaconda-navigator
3) restart your computer (I don't know if it will work by only restarting the conda navigator). Your new environment should be list in your anaconda navigator.

Spyder does not run in Anaconda virtual environment on Windows 10

This is my first post here. I tried to find an answer to this question but to no avail.
Just installed Anaconda2 (2.7.11 Python kernel) on my Win10 machine. I am trying to learn the conda command. Here is my problem.
I go to the Anaconda prompt window.
I create a virtual environmant with conda create -n myenv python=3.4 command.
I activate the environment with activate myenv.
When I list the environmants with conda env list it shows as active (star next to it).
When I start python from a command line it shows me that it is running 3.4.
The same with ipython.
When I type spyder it opens the spyder window but shows me 2.7.11. This is confirmed by running print(sys.version).
Am I doing anything wrong or is this just windows 10 problem.
Thanks in advance,
Andy
When you type spyder, the search for this command begins in the paths that the conda environment created. If it cannot find it there, it will go and search at other places. In your case in the paths of the default Anaconda install. So after you activate your environment:
activate myenv
you need to install sypder inside this environment:
(myenv) conda install spyder
where (myenv) indicates the active environment.
Change the Python interpreter in the Preference menu. See pic below.
you just have to write
conda create -n myenv python=3.4 spyder
conda activate myenv
spyder
and for deactivation later on ..
conda deactivate
Note: using Windows 10.
To use Spyder in a particular environment, there are at least two options:
conda install spyder into that environment - the problem, for me, is that it also wants to install a large number of other packages that I don't want or need in that environment.
I just want to use Spyder for interactive programming/investigation using the particular packages that I have chosen to install in a particular environment. The solution to this is option 2.
Note: I installed Anaconda initially and so have Spyder in the Anaconda environment.
Copy the relevant Spyder files from the Anaconda environment into the particular environment(s) you want to use Spyder in:
From: C:\Users\User\Anaconda\Lib\site-packages
Copy: spyderlib & spyderplugins Folders
To: C:\Users\User\Anaconda\envs\[Environment_Name]\Lib\site-packages
From: C:\Users\User\Anaconda\Scripts
Copy: spyder.exe, spyder.ico, spyder_light.ico & spyder-script.py Files
To: C:\Users\User\Anaconda\envs\[Environment_Name]\Scripts
To use Spyder in the desired environment:
Activate the environment
(Environment_Name) prompt> spyder
This works for me!

Resources