I'm using VScode on windows, and the VScode terminal.
I installed virtualEnv (with >>> pip install virtualenv )and everything was working correctly.
Then I installed git, and after this, I couldn't deactivate the virtual environment and I don't see any errors too!
I use this command:
MyVirtualEnvName\scripts\deactivate
my problem is: now I can't deactivate virtualenv and the above command isn't working! how can I deactivate this?
try just deactivate in the shell, instead of the path to the deactivate script
Go inside Scripts folder by running cd command.
Then just type deactivate.
It will recognize and will run the deactivate.bat file.
Related
I installed virtual environment using (pip3 install virtualenv). it was installed but when I check. This comes up.
faculty#Facultys-MacBook-Pro ~ % virtualenv --version
zsh: command not found: virtualenv
I believe you might not have you python libs in your path. which is why it is not found by zsh.
Quick fix
I believe you can go with:
python3 -m virtualenv <name of the virtual env>
This should hopefully work and create your virtualenv in the current folder you are in.
Permanent fix
Some smarter people already went through this issue have a look pip installs packages successfully, but executables not found from command line
You need to make sure the following thing:
virtualenv has been only installed in the folder you used to run the pip commmand. There should be a new directory called venv now. Try opening the terminal inside the venv folder bin and type the command again.
On command $which python3$ , the location says /opt/homebrew/bin/python3 on my Mac. Is this okay for python to be in other directory than /usr/local/ ?
Yes. It will work. I mean if you change the location of installation directory, mac os will recognize it and python3 instruction will work.
Yeah it's absolutely ok. But it's better to create a project wise virtual env so that you don't messed up installing so many third party libraries globally in your system which could break system tools and other projects.
Installing vitualenv:
python3 -m pip install --user virtualenv
Creating a virtual environment.
cd {{your project directory}}
python3 -m venv env
Activate the virtualenv:
source env/bin/activate
Now if you run which python you will see the python is from your newly created virtual env.
I created a virtual environment with venv.
venv --python=/workspace/dev/python3.9 /var_path/var_virtual_env
In Visual Studio Code(portable version -Linux) I have set:
"python.venvPath": "/var_path/var_virtual_env",
"python.formatting.provider": "black"
The environment is seen in VSCode:
Code with python built-ins works without a problem.
From VS Code terminal with virtual environment activated using pip I installed different packages and I expected the packages to be imported in the virtual environment, but instead seems that they are installed in the/home/user_name/local/lib/python3.6.
Also I noticed that the configurations likepylint.d etc are at same location in "local". The pylint was set thru VSCode.
To fix it I installed the packages in the environment outside VSCode, but the editor doesn't sees them. Example httpx:
But they are in the environment, pip freeze output:
How can I fix this ?
In a terminal where the scarlette environment is activated, copy the output of which python.
Set in settings.json the following line:
{
"python.pythonPath": "paste_the_output_here"
....
}
I don't know if it will work in your case but that did the trick for me several times.
Click on:
And then choose python from venv.
Let know what happened.
I think virtual env is ok, but you didn't activated it in console.
And also I think it will be more intuitive if you create venv relatively, in the same folder as app, then just add it to .gitignore and .dockerignore
Execute this command to create virtual environment:
python -m venv .venv --prompt ${PWD##*/}
Then activate:
source .venv/bin/activate
More advanced:
echo "creating virtual environment"
python -m venv .venv --prompt ${PWD##*/}
echo "upgrading pip & wheel"
.venv/bin/python -m pip install -U pip
.venv/bin/pip install wheel
echo "installing dependencies from requirements.txt"
.venv/bin/pip install -r requirements.txt
Then activate:
source .venv/bin/activate
(You can also activate by opening new terminal instance in vscode, or aby destroying current one and opening new)
There is no activate script in my virtual environment's bin folder.
Only files are: python, python3, python3.9.
How to fix my environment without deleting it? I'm using venv not virtualenv. I'm using Linux.
My problem is similar to this one -
There is no activate when I am trying to run my virtual env
One of answers says I should run.
python3.7 -m venv venv
But I don't understand this syntax. Should I literally write python3.9 -m venv venv into my terminal? Will it fix my enviroment?
Also I want to say that newly created environments work as expected and all the others too.
I had this problem with python 3.10, I had to install venv for my version otherwise I was missing the activate script. (I am using the deadsnake ppa on ubuntu) after this the activate script appears when creating new venv.
sudo apt-get install python3.9-venv
I documented the full python 3.10 on Ubuntu installation here
i think this is helpfull for you
but for basic use it like this:
python3.7 -m venv myenvname
source myenvname/bin/activate
and if activate isnt there try to find that in sub directories
So I am using vscode with conda (for a django project), and trying to activate my virtual environment named "venv".
And it goes from:
(base) C:\Users\User\Desktop\pfa-master\pfa-master\venv\Scripts> .\activate
to something like this:
(venv) (base) C:\Users\User\Desktop\pfa-master\pfa-master\venv\Scripts>
And if I try to find out Python version, it shows error like this:
(venv) (base) C:\Users\User\Desktop\pfa-master\pfa-master>which python
'which' is not recognized as an internal or external command,
operable program or batch file.
Note: I have Python in environment variables for anaconda.
What am I doing wrong?
You need to deactivate Conda. In terminal, conda deactivate should get rid of (base). When you want to reactivate Conda, conda activate.
You have two virtual environments active.
conda and virtualenv are both package manager and environment management system :
(base) is from conda : https://docs.conda.io/en/latest/
(venv) is from virtualenv : https://virtualenv.pypa.io/en/latest/
If you want to use (venv) only, you need to deactivate conda : conda deactivate
If you want to use (base) only, you need to delete the venv directory from your repository :
sudo rm -rf venv. Command differs because you are using Windows.
Use the command python -V to find the installed python version and pip -V to get the current pip version.
if you have anaconda in your environmental PATH, try activate venv. Also, try restarting VScode sometimes it glitches.
first you can use activate to activate venv, and then use conda deactivate to deactivate (base).
Try this command:
python --version