I have a conda env named py36 with python3.6 in it: (yea I know it is deprecated - there's a surprising amount of legacy code on older/unsupported versions..)
(py36) 11:34:52/py36 $conda env list
# conda environments:
#
base /Users/steve/opt/miniconda3
..
py36 * /Users/steve/opt/miniconda3/envs/py36
Let's double-check the python version:
(py36) 11:35:12/py36 $/Users/steve/opt/miniconda3/envs/py36/bin/python -V
Python 3.6.7 :: Anaconda, Inc.
Let's activate it:
$conda activate py36
(py36) $python -V
Python 3.9.12
So then why was the version unchanged? I searched for answers and discovered there is an open bug with conda PATH not set by conda activate . The main workaround - to include a package when creating the env - did not work. This is specifically what I tried
conda create -n py366 PYTHON=3.6 pip
$conda activate py366
$ (py366) $python -V
Python 3.9.12
Can anyone chime in on a workaround?
I see that there is an update to my $PATH in the .bash_profile below the section for conda_init() . Moving the $PATH modification before the conda_init() within the .bash_profile resolved this issue.
Related
is there a way to easily switch from conda environments to my system's native python environment? When I have conda activated, and I run bash or exec bash it doesn't seem to work, and when I run python it uses conda's python and it's not using the system python path. The only way I've been able to get this to work is by restarting the terminal entirely. Is there a faster way to do this?
(I've actually removed the conda init block from my ~/.bashrc and I run it manually every time I want to use conda's python.)
You have two options:
Just deactivate the base environment:
(base) $ conda deactivate
$
Configure your conda to not activate the base environment on startup.
(base) $ conda config --set auto_activate_base false
<restart shell>
$
# use the system python
$ python
# to use conda you'll need to activate it first
$ conda activate
(base) $ python
The conda command you're looking for is deactivate.
Suppose you have activated the myproject environment.
$ conda deactivate
Now your environment is base, as seen by which python,
or conda info --envs.
$ conda deactivate
Now you're not using conda at all, and which python shows the system
interpreter, likely /usr/bin/python.
This may be a bit of a hack, but what about adding an alias pointing to the system python before the conda block in .bashrc? Assuming you don't want to use "conda deactivate" and lose the environment completely.
alias syspython=`which python`
# >>> conda initalize >>>
...
You should then be able to use the system python in a conda env like so:
syspython file.py ...
I am having trouble with pyenv after updating my macOS to 11.5. This is what I tried:
$ pyenv install 3.8.11 --skip-existing
$ pyenv virtualenv 3.8.11 >virtual env name<
$ pyenv local >virtual env name<
All of this works fine. Running pyenv local results in printing my virtual env's name. But I can't install dependancies or do anything with pip:
$ pip freeze
python >virtual env name< not installed
I tried following this answer, but I still have the same problem.
Note: This is also happening with virtual envs that were previously working pre-update.
Turns out the issue was with updating pyenv and not macOS. All I had to do was add the following lines to my ~./zshrc (or ~/.zprofile:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
How can I load in these packages I've just installed in Anaconda Python? I've installed Anaconda, and installed a package with the following commands in my mac terminal:
conda activate base
conda install pip
pip install datascience
pip install okpy
I can verify that these have been installed by running conda list, and both packages show up in that list.
I've searched around, and there appears to be some difficulty when I've had other versions of Python on my machine. I've tried to remove many of them, but when I type which python I get /usr/bin/python. Here's what my .bash_profile file looks like:
# added by Anaconda3 2019.07 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/adityakamath/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/Users/adityakamath/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/adityakamath/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/Users/adityakamath/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
How can I change my settings so that, when I start up Jupyter Notebook using the Anaconda navigator, I will be able to import these libraries? The import statement I need to run is from client.api.notebook import Notebook.
If you have multiple versions of python you should run in a virtual environment. You can create a virtual environment by typying
conda create -n yourenvname python=x.x anaconda
where python=x.x is the version of python to use in your environment.
Then run
activate yourenvname
.
After you activate your environment then type
pip3 install client
I'm using anaconda interpreter, can you please tell me how to install django by creating conda environment in different drive (other than C drive).
Thank you
You could use the -p or --prefix argument in conda create to save the environment to a specific location.
conda create -p D:/path/to/my/env django
The only difference here is that the environment will not be in the list provided by anaconda and thus has to be explicitly activated with its path.
For example this is what it looks like on OS X:
conda create -p ~/Desktop/test -y -q django
Package plan for installation in environment /Users/grr/Desktop/test:
The following NEW packages will be INSTALLED:
ca-certificates: 2017.08.26-ha1e5d58_0
certifi: 2018.1.18-py36_0
django: 1.11.8-py36hd476221_0
libcxx: 4.0.1-h579ed51_0
libcxxabi: 4.0.1-hebd6815_0
libedit: 3.1-hb4e282d_0
libffi: 3.2.1-h475c297_4
ncurses: 6.0-hd04f020_2
openssl: 1.0.2n-hdbc3d79_0
pip: 9.0.1-py36h1555ced_4
python: 3.6.4-hc167b69_1
pytz: 2017.3-py36hf0bf824_0
readline: 7.0-hc1231fa_4
setuptools: 38.4.0-py36_0
sqlite: 3.21.0-h3efe00b_0
tk: 8.6.7-h35a86e2_3
wheel: 0.30.0-py36h5eb2c71_1
xz: 5.2.3-h0278029_2
zlib: 1.2.11-hf3cbc9b_2
# conda environments:
#
Tensorflow /Users/grr/anaconda/envs/Tensorflow
cbc /Users/grr/anaconda/envs/cbc
py27 /Users/grr/anaconda/envs/py27
py35 /Users/grr/anaconda/envs/py35
root * /Users/grr/anaconda
source activate ~/Desktop/test
(/Users/grr/Desktop/test) Diouf: grr ~ $
On Windows you would just omit source during activation.
I'm trying to create a virtual environment. I've followed steps from both Conda and Medium.
Everything works fine until I need to source the new environment:
conda info -e
# conda environments:
#
base * /Users/fwrenn/anaconda3
test_env /Users/fwrenn/anaconda3/envs/test_env
source ~/anaconda3/bin/activate test_env
_CONDA_ROOT=/Users/fwrenn/anaconda3: Command not found.
Badly placed ()'s.
I can't figure out the problem. Searching on here has solutions that say adding lines to your bash_profile file, but I don't work in Bash, only C shell (csh). It looks like it's unable to build the directory path in activate.
My particulars:
OS X
Output of python --version:
Python 3.6.3 :: Anaconda custom (64-bit)
Output of conda --version:
conda 4.4.7
I am not sure what causes the problem in your case, but code below works for me without any issues (OS X, the same version of Conda as yours).
Creation of the environment
conda create -n test_env python=3.6.3 anaconda
Some explanation of the documentation of conda create is not clear:
-n test_env sets name of the environment to test_env
python=3.6.3 anaconda says that you want to use python in version 3.6.3 in this environment (exactly the one you have, and you can use a different one if you need it) and package anaconda. You can put all the things you need there, separated with spaces, e.g., sqlite matplotlib requests and specify their versions the same way as for python.
Activation
conda activate test_env
Deactivation
conda deactivate
Getting rid of it
conda remove -n test_env --all
Check if Conda is installed
conda -V
Check if Conda is up to date
conda update conda
Create a virtual environment
conda create -n yourenvname python=x.x anaconda
Activate your virtual environment
source activate yourenvname
Install additional Python packages to a virtual environment
conda install -n yourenvname [package]
Deactivate your virtual environment
source deactivate
Delete the virtual environment
conda remove -n yourenvname --all
I was able to solve my problem. Executing the source activate test_env command wasn't picking up my .bash_profile, and I normally work in tcsh. Simply starting a subprocess in Bash was enough to get activate working. I guess I assumed, incorrectly, that the activate command would start a child process in Bash and use Bash environment variables.
> conda info -e
> # conda environments:
> #
> base * ~/anaconda3
> test_env ~/anaconda3/envs/test_env
> bash
~$ source ~/anaconda3/bin/activate test_env
(test_env) ~$
(test_env) ~$ conda info -e
# conda environments:
#
test_env * ~/anaconda3/envs/test_env
root ~/anaconda3