Comments (16)
Here's some example how auto-activation works.
Let's say if you have 3 directories named foo
, bar
and baz
. The foo
uses CPython 2.7.8 as the local version inside the directory. The bar
uses a virtual environment named venv27
as the local version. And, the baz
uses a virtual environment named venv34
as the local version.
With this configuration, when you cd
to the directory bar
or baz
, the pyenv
will automatically activate the specified virtual environment into your shell.
% pyenv versions
system
2.7.8
* 3.4.2 (set by /home/yyuu/.pyenv/version)
venv27
venv34
% mkdir foo bar baz
% echo 2.7.8 > foo/.python-version
% echo venv27 > bar/.python-version
% echo venv34 > baz/.python-version
% cd foo
% python --version
Python 2.7.8
% cd -
~/
% cd bar
pyenv-virtualenv: activate venv27
(venv27)% python --version
Python 2.7.8
(venv27)% cd -
~/
pyenv-virtualenv: deactivate venv27
% cd baz
~/
pyenv-virtualenv: activate venv34
(venv34)% python --version
Python 3.4.2
(venv34)% cd -
~/
pyenv-virtualenv: deactivate venv34
from pyenv-virtualenv.
There are any references to ${PYENV_ACTIVATED}
and ${PYENV_DEACTIVATED}
in pyenv-virtualenv
. It uses ${PYENV_ACTIVATE}
and ${PYENV_DEACTIVATE}
to store the state of activation. Please see also the relating source to understand the behaviour of the auto-activation.
https://github.com/yyuu/pyenv-virtualenv/blob/a02eb0a396f03b70bb6ed9d215cf298f471d8a49/bin/pyenv-virtualenv-init#L114
https://github.com/yyuu/pyenv-virtualenv/blob/a02eb0a396f03b70bb6ed9d215cf298f471d8a49/bin/pyenv-sh-activate#L112
https://github.com/yyuu/pyenv-virtualenv/blob/a02eb0a396f03b70bb6ed9d215cf298f471d8a49/bin/pyenv-sh-deactivate#L62
from pyenv-virtualenv.
Actually, brew's pyenv-virtualenv
doesn't install as a plugin of pyenv
, but it isn't matter. It is just simply installed into /usr/local
(brew --prefix
) and pyenv
can find the plugin's executables if it is in $PATH
. It is working expectedly for now.
from pyenv-virtualenv.
Thanks for your reply. Now i get it - the notes are not clear at all with regards to how auto-activation works - i.e there is no mention that you can / should run pyenv local <version | virtualenv name >
or the echo above.
Now i followed the below steps, which match yours but for some reason i can't get the line which indicate what steps took place
[dani@localhost in ~]# pyenv versions
* system (set by /usr/local/opt/pyenv/version)
3.4.2
[dani@localhost in ~]# mkdir dani
[dani@localhost in ~]# cd dani/
[dani@localhost in ~/dani]# pyenv virtualenv 3.4.2 ra4
Ignoring indexes: https://pypi.python.org/simple/
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/local/var/lib/pyenv/versions/ra4/lib/python3.4/site-packages
Requirement already satisfied (use --upgrade to upgrade): pip in /usr/local/var/lib/pyenv/versions/ra4/lib/python3.4/site-packages
Cleaning up...
[dani@localhost in ~/dani]# pyenv local ra4
[dani@localhost in ~/dani]# cat .python-version
ra4
[dani@localhost in ~/dani]# cd
[dani@localhost in ~]# pyenv versions
* system (set by /usr/local/opt/pyenv/version)
3.4.2
ra4
[dani@localhost in ~]# cd dani/
[dani@localhost in ~/dani]# pyenv versions
system
3.4.2
* ra4 (set by /Users/dani/dani/.python-version)
[dani@localhost in ~/dani]# python -V
Python 3.4.2
[dani@localhost in ~/dani]# cd
[dani@localhost in ~]# python -V
Python 2.7.6
[dani@localhost in ~]# pyenv versions
* system (set by /usr/local/opt/pyenv/version)
3.4.2
ra4
[dani@localhost in ~]#
As you can see when i go _inside_ dani directory, it gets auto activated but there is no line output as below to indicate if something happen
pyenv-virtualenv: activate ra4
nor having something like
(ra4)[dani@localhost in ~/dani]#
Any idea?
Thx,
Dani
from pyenv-virtualenv.
@yyuu - can you please help on the above question?
Maybe you can paste:
- echo $PATH
- if you using BASH, maybe you can say which version
- is the PROMPT_COMMAND controlled by
${virtualenv}/bin/activate
? If yes, how it it called in the auto activation scenario?
Many thanks in advance
from pyenv-virtualenv.
I'm using GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu)
on Debian GNU/Linux sid. pyenv
and pyenv-virtualenv
are installed from latest master
on GH. Actually, my default shell is zsh (zsh 5.0.7 (x86_64-pc-linux-gnu)
) and PATH
is /usr/local/heroku/bin:/home/yyuu/.rbenv/shims:/home/yyuu/.rbenv/bin:/home/yyuu/.pyenv/shims:/home/yyuu/.pyenv/bin:/usr/lib/jvm/default-java/bin:/home/yyuu/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/sbin:/usr/sbin:/sbin
.
pyenv / pyenv-virtualenv will do nothing about shell's prompt. During the auto-activation scenario, ${virtualenv}/bin/activate
is called via pyenv-sh-activate
and it will be modify user's shell prompt.
https://github.com/yyuu/pyenv-virtualenv/blob/58e93f9e0d7fa45e44bb2f13caff49668e1cad47/bin/pyenv-virtualenv-init#L123
https://github.com/yyuu/pyenv-virtualenv/blob/58e93f9e0d7fa45e44bb2f13caff49668e1cad47/bin/pyenv-sh-activate#L115
from pyenv-virtualenv.
FWIW, I pushed a runnable docker image yyuu/pyenv-virtualenv:issue52
at https://registry.hub.docker.com/u/yyuu/pyenv-virtualenv/ . You can try running pyenv-virtualenv with auto-activation feature from the image.
% docker run -it yyuu/pyenv-virtualenv:issue52 bash
root@d35f7bb54946:/# cat /dani/.python-version
ra4
root@d35f7bb54946:/# pyenv versions
3.4.2
ra4
root@d35f7bb54946:/# cd /dani
pyenv-virtualenv: activate ra4
(ra4) root@d35f7bb54946:/dani# pyenv versions
system
3.4.2
* ra4 (set by /dani/.python-version)
(ra4) root@d35f7bb54946:/dani# python -V
Python 3.4.2
(ra4) root@d35f7bb54946:/dani# cd /
pyenv-virtualenv: deactivate ra4
root@d35f7bb54946:/# pyenv versions
3.4.2
ra4
The following is the Dockerfile I used to create the yyuu/pyenv-virtualenv:issue52
.
FROM ubuntu:14.04
MAINTAINER Yamashita, Yuu <[email protected]>
ENV PATH /root/.pyenv/shims:/root/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get --quiet --yes update
RUN apt-get --quiet --yes upgrade
RUN apt-get --quiet --yes install build-essential curl git libbz2-dev libreadline-dev libsqlite3-dev libssl-dev patch zlib1g-dev
RUN git clone --quiet https://github.com/yyuu/pyenv.git /root/.pyenv
RUN cd /root/.pyenv && git reset --hard 35aed21
RUN git clone --quiet https://github.com/yyuu/pyenv-virtualenv.git /root/.pyenv/plugins/pyenv-virtualenv
RUN cd /root/.pyenv/plugins/pyenv-virtualenv && git reset --hard 58e93f9
RUN echo 'eval "$(pyenv init -)"' >> /root/.profile
RUN echo 'eval "$(pyenv virtualenv-init -)"' >> /root/.profile
RUN pyenv install 3.4.2
RUN pyenv rehash
RUN pyenv virtualenv 3.4.2 ra4
RUN mkdir /dani && cd /dani && pyenv local ra4
RUN echo 'exec /bin/bash -l "$@"' > /start && chmod 755 /start
ENTRYPOINT /start
from pyenv-virtualenv.
Thanks for the dockerfile. I don't get it how it doesn't work on my Mac. Anyway, for now i can live with the manual activation/ deactivation + shell unset.
Dani
from pyenv-virtualenv.
I'm using docker
on OS X with boot2docker
😃 (honestly, usually I'm living on Debian GNU/Linux on VMware Fusion, though)
I suspect that there might be some configuration issue in your installation. If you found something, please let me know.
from pyenv-virtualenv.
FYI before i upgraded to latest version (using git pull
), the prompt was working when the virtualenv was activated.
After the upgrade to latest/ greatest my prompt is no longer shown after activation.
from pyenv-virtualenv.
It is expected behaviour after #104. Currently we're not depending activate
script created by virtualenv and it will not change the users' shell prompt anymore.
from pyenv-virtualenv.
@yyuu while i do understand the work done to get anaconda env work better i'd appreciate if you add back the prompt to signal is active - otherwise is a massive killer from user experience pov.
from pyenv-virtualenv.
Hm, okay. I understood your request. I might revert them at least for non-fish. (I don't want to revert it for fish
since the original code had some problems with oh-my-fish, as far as I remember)
from pyenv-virtualenv.
@yyuu or if you want you can add a flag which could be set in the .bashrc (same way you set auto activation) to behave as of now or the old way - i.e change prompt to reflect the virtualenv name
Thanks!
P.S - virtualenv project behavior does show/ change the prompt to reflect the activation
from pyenv-virtualenv.
Pushed 3152718 to restore prompt for non-fish.
from pyenv-virtualenv.
Awesome, it works as expected, thank you!
P.S - suggestion: if in the future you planning to remove the prompt (w/o any flag to enable) please make a big note in the readme, in this way we can hold the upgrade ;)
from pyenv-virtualenv.
Related Issues (20)
- Activate virtualenv: Example
- `pyenv virtualenvs` failure on macOS Big Sur HOT 1
- Something like virtualenv-clone HOT 7
- [FR] Local virtualvenvs + registering them / using them through `.python-version` HOT 14
- Force creating venv with same name doesn't update Python version
- Set CONDA_PROMPT_MODIFIER env var when activating conda environment HOT 5
- Env's name disappears from the prompt when spawning a subshell HOT 6
- python3-config (along with other tools) does not respect the version virtualenv hook on HOT 6
- pyenv deactivate doesn't deactivate env HOT 1
- pyenv virtualenv does not correctly link the c++ libraries associated to the python package
- New release? HOT 3
- Latest version HOT 1
- Incorrect version reported by `pyenv virtualenv --version` HOT 1
- Cannot create new virtualenv with "system" Python if it's 3.11+ HOT 1
- Hooks for virtualenv-delete HOT 1
- Hooks don't work under /usr/share/pyenv/plugins
- Virtualenv not isolated HOT 1
- Don't use `.python-version` for auto-activation HOT 3
- "tox: command not found" despite tox being present in the active environment HOT 1
- Unable to use `venv/bin/activate` when the virtual environment of pyenv-virtualenv is set. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyenv-virtualenv.