Reputation: 542
I am on a freshly installed Ubuntu 16.04 and in view of developing with recent versions of pandas I installed Python 3.6.0 using a virtual environment.
A reason for choosing 3.6.0 was because I read somewhere that this version of Python could deal with virtual environments natively, i.e. without installing anything else [anyway to install 3.6.0 itself without replacing the system wide Python, which would have been almost surely wrong, I actually had to provide a virtual environment before].
I did it optimistically thinking that everything would go in the right direction (including my knowledge) and so, without caring too much about the differences between: pyenv, pyenv-virtualenv, pyvenv, etc...
So I don't remember well what I installed, anyway I used only apt
and pip
/pip3
, trying to confine changes within the virtualenv as soon as it became available.
I loosely followed this tutorial except (maybe) that I didn't create a directory for the virtualenvs (the $ mkdir ~/.virtualenvs
command).
Now my user is stuck within the (general)
environment and I can't get out.
Right from the start after the login, without activating any environment, Bash gives me a modified prompt, and it seems I can't get the usual prompt by deactivate
, source deactivate
, etc...
(general) $ deactivate
pyenv-virtualenv: deactivate must be sourced. Run 'source deactivate' instead of 'deactivate'
(general) $ source deactivate
pyenv-virtualenv: deactivate 3.6.0/envs/general
(general) $ pyvenv deactivate
pyenv: pyvenv: command not found
The `pyvenv` command exists in these Python versions: 3.6.0
(general) $
You see that the (general)
prefix remains in the prompt.
I have also had symptoms that this pyenv
/virtualenv
setup is affecting system activities (e.g. while trying to install hplip
from the command line, the installer got confused when trying to recognize my OS, and ultimately failed - I had to do it from another user, and then it worked), so I need to revert this to a clean state.
NB. I am not that sure that my installation is really that wrong, maybe it's just me issuing the wrong commands or some common pitfall I have incurred in.
deactivate
the (general) environment?I have already read this question but it wasn't so tied to my case
This one seems more related, in that it highlights that
python venv
should be preferred;But still I am unsure of what to uninstall before installing them in case.
Here are the outputs of TAB completions, commands, and a directory listing, to show a bit of which environment I am in:
(general) $ cat .py <TAB>
.pyenv/ .python_history
(general) $ cat .pyenv/ <TAB>
.agignore completions/ LICENSE shims/ versions/
bin/ CONDUCT.md Makefile src/ .vimrc
cache/ .git/ plugins/ test/
CHANGELOG.md .gitignore pyenv.d/ .travis.yml
COMMANDS.md libexec/ README.md version
(general) $ cat .pyenv/version
general
(general) $ ls -l ~/.pyenv/versions
totale 12
drwxrwxr-x 3 myuser myuser 4096 apr 20 13:50 ./
drwxrwxr-x 13 myuser myuser 4096 apr 20 13:50 ../
drwxr-xr-x 7 myuser myuser 4096 apr 20 13:50 3.6.0/
lrwxrwxrwx 1 myuser myuser 48 apr 20 13:50 general -> /home/myuser/.pyenv/versions/3.6.0/envs/general/
I tried listing what installed, but I'm afraid that with pip3 list
the answer I get is for the env where I am stuck, and that this is masking anything that I installed before getting to it.
May it just be that I mistakenly installed pyenv
from my home directory? Would it be enough to delete/move the .pyenv
directory? I am not confident enough to do it without asking.
Upvotes: 11
Views: 19300
Reputation: 189387
Your mental model of what these modules do is wrong.
pyenv
doesn't really have a "deactivate" feature. It lets you choose between a number of independent Python installations, but you would basically always be using one of them - unless you get rid of pyenv
entirely. pyenv shell .
effectively deactivates pyenv
for the time being in the current shell instance, and if you want to remove it from your configuration entirely, you want to remove the pyenv
commands from your shell's login files: they would typically look something like
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
where the latter is an optional add-on which you might not have installed.
You can mix pyenv
with regular virtual environments; for example, you could run pyenv shell 3.8.9
and then with that active run python -m venv thisenv
which will create thisenv
in the current directory with a link to the selected Python version; then running source thisenv/bin/activate
will activate the virtual environment, so that python
or python3
runs the Python version you had active in pyenv
when you created the environment, and you can subsequently deactivate
that to return to whatever you had before.
As a quick hack, you can also run $(pyenv root)/versions/3.8.9/bin/python -m venv thisenv
to create the environment without touching the pyenv shell
setting.
The pyenv-virtualenv
add-on plugin has its own set of features, with a slightly different set of use cases. You create those with pyenv virtualenv
, activate with pyenv activate
, and deactivate with pyenv deactivate
. These environments are stored alongside the pyenv
Python versions in a central place in your home directory, not in the current directory.
Upvotes: 2
Reputation: 1644
EDIT-[22/11/22]---> BELOW ANSWER IS FROM 2018 - maybe i never got to DEACTIVATE and did only manage to UN-INSTALL
The way to DEACTIVATE the default PyEnv General is --pyenv uninstall 3.6.0/envs/general
pyenv-virtualenv: remove /home/dhankar/.pyenv/versions/3.6.0/envs/general? y
dhankar@dhankar-VPCEB44EN:~/.pyenv$
to doubly ensure that the PyENV has been removed --
dhankar@dhankar-VPCEB44EN:~/.pyenv$ pyenv versions
pyenv: version `general' is not installed (set by /home/dhankar/.pyenv/version)
system
3.6.0
3.6.5
dhankar@dhankar-VPCEB44EN:~/.pyenv$
Also so that its documented - am sharing the terminal output of the same command , earlier before the Un-Install.
(general) dhankar@dhankar-VPCEB44EN:~/.pyenv$ pyenv versions
system
3.6.0
3.6.0/envs/general
3.6.5
* general (set by /home/dhankar/.pyenv/version)
(general) dhankar@dhankar-VPCEB44EN:~/.pyenv$
Upvotes: 1