How to deactivate venv while using fish? - python

I have installed venv using python3 with fish like and activated using env/bin/activate.fish, but there is no deactivate.fish in env/bin/
➜ ls env/bin/
activate activate.fish easy_install pip pip3.7 python3
activate.csh chardetect easy_install-3.7 pip3 python yapf
how can I deactivate venv?

In opposite to activate, deactivate is implemented as a shell function, not as a shell script or binary in env/bin. You can verify that by running:
type -t deactivate
function
To run the function and deactivate the virtualenv, just run deactivate
PS: This behaviour is the same for all shells, it is not special to fish.

Related

Get a fresh bash without conda

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 ...

pyenv: "python >virtual env name< not installed"

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)"

cmder virtualenv name showing

I am new to cmder, when ever I try to create virtualenv for python, django and activate it using ./Scripts/activate
This is cmder :
F:\python\django\tweeter
λ .\Scripts\activate
F:\python\django\tweeter
λ
This is Git bash :
Ahmed#DESKTOP-VJ37FJE MINGW64 /f/python/django/tweeter
$ source ./Scripts/activate
(tweeter)
Ahmed#DESKTOP-VJ37FJE MINGW64 /f/python/django/tweeter
$
(tweeter)
Ahmed#DESKTOP-VJ37FJE MINGW64 /f/python/django/tweeter
$
As you can see when I use Git bash, it shows me virtualenv name when I activate it. But it not goes same for cmder.

Virtual environment doesn't work on Cloud9

Cloud9 (an online ide) doesn't seem to support my virtual environment:
me:~/workspace/dir (master) $ source venv/bin/activate
(venv) me:~/workspace/dir (master) $ which python
/usr/bin/python
This same virtual directory worked fine on my local machine:
(venv) me$ which python
/Users/me/dir2/dir/venv/bin/python
How can I fix this?
The following works for me.
sudo apt-get install python3.5-venv
python3.5 -m venv --clear ./mypy3.5/
source ./mypy3.5/bin/activate
It uses the
(mypy3.5) $ which python
/home/ubuntu/mypy3.5/bin/python
But there is a gotcha which might have been your problem. The python3 -m venv uses soft links to how your python resolves in your environment. I had Python 3.3, 3.4 and 3.5 installed in /usr/local so the /usr/local/bin/python3 would change and break my Python3 venv. Note that "python3" is evaluated for the environment not for an absolute path. To be careful, when there are more than one Python 3 on you system, create your virtual environment with an explicit path like the following.
/usr/bin/python3.5 -m venv --clear ./mypy3.5/
source ./mypy3.5/bin/activate
ls -l $(which python3.5)
/home/ubuntu/mypy3.5/bin/python3.5 -> /usr/bin/python3.5*

How come I can not activate my Virtual Python Environment with 'source env/bin/activate' command?

I am trying to activate my Virtual Python Environment to use with Pylons but I think I am executing the commands wrong.
jem#jem-laptop:~$ source env/bin/activate
bash: env/bin/activate: No such file or directory
What am I doing wrong?
How should I do it right?
I realize I had to do
jem#jem-laptop:~$ ls
Desktop examples.desktop Public shortener.rb
Documents Mac4Lin_v1.0 ruby-1.9.1-p378 Templates
Downloads Music rubygems-1.3.7 Videos
Dropbox Pictures setcolors.vim virtualenv.py
And here we see virtualenv.py. From here I just had to
jem#jem-laptop:~$ virtualenv ENV
New python executable in ENV/bin/python
Installing setuptools............done.
And then
jem#jem-laptop:~$ source ENV/bin/activate
(ENV)jem#jem-laptop:~$ deactivate
jem#jem-laptop:~$
Solved :)
I usually do it this way:
$ cd the_project_dir
$ . bin/activate
(the_project)$ _
I need to be in the project directory anyway to go on with the work.
Obviously the_project_dir is the name of a directory where you have created a virtualenv.
In 2.7 version I used this command:
$ cd project_name
$ virtualenv venv --distribute
$ source venv/Scripts/activate
(venv)
I would recommend using virtualenvwrapper. It makes working with virtualenv a lot simpler, especially if you have more than one virtualenv.
Simple fix:
$ virtualenv env
$ cd env/Scripts/
$ . activate
On FreeBSD I solved this doing following:
# ls mypienv
# mypienv/bin/activate
mypienv/bin/activate: Permission denied.
# chmod +x mypienv/bin/activate
# mypienv/bin/activate
Missing '}'.
And you see that script not working but:
# ls mypienv/bin/
activate activate.fish easy_install-2.7 pip2.7 python2
activate_this.py activate.ps1 pip python python2.7
activate.csh easy_install pip2 python-config wheel
Finaly:
# python mypienv/bin/activate_this.py
And it worked!
P.S. I am new with python python verions 2.7
env/Scripts/activate worked for me.
For Windows, the following worked for me:
C:\.virtualenvs\env\Scripts>activate.bat

Categories

Resources