Anaconda virtual environment not recognizing Python - python

Whenever I run the commands which conda, which pip, and which python in the base environment, it works fine but whenever I activate the virtual environment using the conda activate command it doesn't recognize those and says no conda/pip in ....
Does anybody have a solution to this? Is this simply a path problem and I need to set a separate path for the virtual environment? Thank you.

Related

Python virtual env not activating

For reference, I'm on Windows 11 using the Bash shell and have Python 3.9.2 installed.
I'm trying to create and activate a Python virtual environment using venv but when I activate it, nothing happens, but no error is given either. My understanding is that once I activate it, my prompt should change to reflect the environment I'm working in, and where python should show it in the virtual environment. Can anyone help clear this up for me?
Bash is unlike the normal command line interfaces on Windows. It uses the shell language, hence you'll not be able to activate it using the same procedure.
Since you generated the file from Windows,
to activate the virtual environment, run:
cd example_venv/Scripts
. activate
Take note of the space after the dot. It's very important for it to be included.
For those using Mac OS or Linux, you can just run:
source <path_to_venv>/bin/activate
where <path_to_venv> is the location of your virtual environment.

When does venv need activation?

When using Pycharm, I make my virtual environment when I m creating a new project and then never have to think about activating it or anything. It works just fine.
When I m using the terminal on my Mac OS, I need to create the virtual environment and then also activate it.
I also have to activate it for VS Code.
How do I know when I need to activate my virtual environment? Thanks.
To activate a virtual environment from the terminal, you need to source a file that the venv module created. This file typically will be in the bin directory of your project (ej. my_project/folder/bin) and will be named activate.
So to activate the environment in your shell you would run the command
source my_project/folder/bin/activate
You should know if you're already IN the virtual environment, when you see the project's name parsed to some part of your shell prompt. If you're already into your virtual environment, you can leave it with the deactivate command.

Python 2.7 Script in Virtual Environment

I am running a Python 2.7 script that has specific dependencies/libraries (contained in a virtual environment) using anaconda prompt. Is there a way to run the script using code in a python 3 .py file in a different environment? Something like a library that allows me to open anaconda prompt in a specific environment (to then run the python 2.7 script). I couldn't seem to find it online. Any pointers would be appreciated.
Well you can select the environment from the drop-down box in the Anaconda Navigator home page if you have your virtual environment in Anaconda itself.
Or you can use
conda activate env-name
If you have your base conda in your terminal as default or else activate using
source ~/.bash_profile
then run
conda activate env-name
Hope this helps.

error when activating anaconda environment

I have tried activating my conda for a while now, when I do conda env list I get an env like this "C:\Users\Allaye\Anaconda3" and I issue this command 'conda activate C:\Users\Allaye\Anaconda3', but when I restart my machine again I still gets the same activate environment error. any help. but write now even the conda command isn't working again..
I don't know what to do now, because it seems when I activate the environment it only on a tempora basics
Activating a conda environment applies to the current shell or terminal window only. That way, you can open several terminals and activate different conda environments in each. It's not a persistent setting, you have to repeat it every time you open a terminal to work in a specific conda environment.
You could define aliases or helper scripts for each environment, so you have to do less typing.

I am trying to add a python interpreter as a Virtualenv Environment at Pycharm using an Anaconda environment

This shows my Anaconda Environment. I created a new environment named "my_env."
However, when I tried to add a Python Interpreter from an existing environment and tried to select my_env from the "envs" folder, there was none.
Can anyone please let me know how I can navigate my "my_env" environment from the second screenshot?
Thanks.
This answer might help.
You need to add the anaconda envs folder to the path, for example:
set PATH=C:\Anaconda\envs\py3x\Scripts;C:\Anaconda\envs\py3x;%PATH%
and once that's done you can activate the environment by using the command:
activate my_env
in the pycharm terminal, and it should activate and show by prefixing the terminal with:
(my_env)

Categories

Resources