Deactivate a pipenv environment - python-3.x

How can I deactivate my pipenv environment?
With other tools I've been able to do something like source deactivate, but that has no affect here.
Create an environment:
pipenv --three
Activate the environment:
source $(pipenv --venv)/bin/activate
But how to deactivate?

To elaborate on Williams' answer a bit more, the expected workflow is to enter the virtualenv using pipenv shell. When you activate the virtualenv that way, the console output now indicates to use exit:
Spawning environment shell (/bin/zsh). Use 'exit' to leave.
Trying to exit the virtualenv with deactivate will leave pipenv in a confused state because you will still be in that spawned shell instance but not in an activated virtualenv.

Using the shell command exit also works.
This worked for me when using deactivate still left me with the error:
Shell for UNKNOWN_VIRTUAL_ENVIRONMENT already activated.
No action taken to avoid nested environments.
After using exit I could successfully switch pipenv instances. This could well be a bug and I should probably report it.

UPDATE: See other answers below. As it has been explained, this works for virtualenv, but pipenv works differently.
Just type deactivate on the command line. See the guide here

Just type "exit", it will take you out of shell.
And if you use "deactivate", then probably you will get this error when you again try to enter in the shell.
Shell for UNKNOWN_VIRTUAL_ENVIRONMENT already activated.
No action taken to avoid nested environments.
So, it is prefer to use "exit" for quick access.

Deactivate from pipenv virtual environment, you can simply run the following command.
deactivate

Please check this topic for answer from contributor perspective:
https://github.com/pypa/pipenv/issues/84#issuecomment-275056943
Spoiler :
pipenv starts a new shell session with the virtualenv pathing instead of changing the pathing in the current shell session. That is why deactivate does not work. you need to exit the shell session. the exit command or CTRL-d will do the trick.

First "deactivate" and then "exit" you will get out of the virtual env. As of now this worked for me.

for the problem caused was due to the previous shell operation in another directory so what i did was exiting my new directory by ctrl+d the exiting the terminal. After that i opened the terminal by alt+t build the directory to the intended directory.then run the pipenv shell command.

Related

How do I upgrade a dumb shell to an interactive shell

I am looking for a way to upgrade my dumb reverse-shell to an interactive shell. I want to upgrade it with Method 3, which can be found here:
https://blog.ropnop.com/upgrading-simple-shells-to-fully-interactive-ttys/
The commands work properly until I try to foreground my shell. 'fg' is working like it is described in the guide but after my shell is foregrounded I am not anymore able to type in commands. It seems like my Shell is frozen. 'reset' would follow now which is necessary to proceed but since I can't type in anything, I cant proceed
Any Suggestions are very welcome
Thanks in advance
Okay, I found it out myself:
First of all I upgraded my dumb shell into a python shell which provides more feature than the original shell but is not completely interactive. Afterwards I used the method above to upgrade the python shell to a TTY shell.
I used:
which Python, Python2, Python3
to check my Python Version.
The command 'which' shows the complete Path and says not found if python is not installed.
Afterwards I have been running the following command (in my case was python3 installed):
python3 -c 'import pty; pty.spawn("/bin/bash")'
If you have another version installed than I had, you need to change python3 to python or python2.
I guess the problem was a bug with the dumb shell but this should fix it.
With the python shell you can follow the instructions I posted above :)
I think the problem occurs when you try to foreground the shell in a different line. If you are having a zsh shell you have to make sure to run the command as stty raw -echo;fg. For other shells you can run it in separate line.enter image description here
[enter image description here][2]

Setting up and activating virtual environment

So, I've been trying to activate my virtual environment in VScode so I could open my Django manage.py and run the server, but for some reason it doesn't seem to activate in my bash terminal. And after running it, I get a "did you forget to activate your virtual environment?". What am I missing here?
In the env folder, there should be an "activate.bat" script, that you can execute to activate your venv.
I think you should open bash in the existing directory and run Scripts\activate
I'd also like to confirm which of the virtual environment you are making use of.

Python Virtual Environment working in Command Prompt, but not in Powershell

I've been trying to get this virtual environment to work with powershell, but I keep getting this error. The virtual environment works in Command Prompt, but not in Powershell, so I've been wondering what I can do to fix that.
There are three (3) "activate" scripts in the venv scripts directory.
PS C:\venv\py39\Scripts> (Get-ChildItem -Filter 'act*').Name
activate
activate.bat
Activate.ps1
These are used in the following shells.
activate # bash
activate.bat # cmd.exe
Activate.ps1 # powershell.exe or pwsh.exe
Use the following for PowerShell.
.\Activate.ps1
The Activate.ps1 script includes a deactivate function. Therefore, no deactivate.ps1 script is needed.
Primary issue is that PowerShell - as you can see on your screenshot - doesn't load commands from the current location by default. Just as it suggests you, try to use .\activate instead of activate.
But that also might not help and lead to other issue connected to the Execution Policies. The command throws some security exceptions after trying to activate the virtual environment. And as it is completly different thing and in order to not duplicate answers, I will redirect you to this thread which should help you with that.
Sometimes I have gotten that error, instead of activate, try .\activate.ps1

pipenv shell working but an error is displayed

If I run the command:
pipenv shell
in my Mac shell, everything works fine and a new virtual environment is created and activated:
.../django_celery_rabbit_flower$ pipenv shell
Launching subshell in virtual environment...
bash: parse_git_branch: command not found
.../django_celery_rabbit_flower$ . /.../django_celery_rabbit_flower-rEt8HW1V/bin/activate
bash: parse_git_branch: command not found
(django_celery_rabbit_flower) .../django_celery_rabbit_flower$
but a bash error is displayed:
bash: parse_git_branch: command not found
I do not understand where it come from. Any idea?
UPDATE
Jen answer trigger a little thought. I have checked my ./bash_profile and I can see the line:
export PS1="\[\033[36m\]\u\[\033[m\]#\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$(parse_git_branch)\$ "
This shows the git branch on the bash prompt. So I believe vscode uses this settings. The folder I am working on is not a git folder. Can I write an if statement to avoid the error being displayed when running the python virtual environment?
Instead make sure that the command does actually exists before running it.
PS1="...."'$(if hash parse_git_branch >/dev/null 2>&1; then parse_git_branch; fi)'"..."

Windows 7: What PATH to set to when using Conda

I've got anaconda installed and was able to create a Python 3.3 environment. I can switch to it and conda info -e shows that I've switched.
However, I'm confused about what to set my PATH variable to. If I hard code it to the exact env then it works, but I thought that the purpose of conda was to be able to switch easily, as well as update and maintain various environments separately.
Perhaps I misunderstood and there's no way around setting my PATH everytime...
In the Windows cmd shell, use the activate and deactivate commands to change the PATH automatically. For instance, if your environment is called python3, run python3 to "activate" (i.e., add to the PATH) the python3 environment. Use deactivate to remove it.

Resources