Comments (22)
/usr/local/opt/pyenv/plugins/pyenv-virtualenv/etc/pyenv.d/exec/virtualenv.bash
isn't the right place for hooks for pyenv-virtualenv
. It'll be used as hooks for pyenv-exec
. Please rename the path enclosing virtualenv.bash
to virtualenv
.
Here's an example.
% mkdir -p "$(pyenv root)/pyenv.d/virtualenv"
% cat <<EOS > "$(pyenv root)/pyenv.d/virtualenv/after.bash"
after_virtualenv 'echo after: Dani'
EOS
% pyenv virtualenv foo
Ignoring indexes: https://pypi.python.org/simple/
Requirement already satisfied (use --upgrade to upgrade): setuptools in /home/yyuu/.pyenv/versions/foo/lib/python3.4/site-packages
Requirement already satisfied (use --upgrade to upgrade): pip in /home/yyuu/.pyenv/versions/foo/lib/python3.4/site-packages
Cleaning up...
after: Dani
from pyenv-virtualenv.
There are before_virtualenv
and after_virtualenv
hooks in pyenv-virtualenv
. pyenv will call those hooks if you setup them. See details for Authoring plugins.
from pyenv-virtualenv.
Thanks for reply.
I've setup them but i think something else is missing or i'm doing something wrong.
The setup i done is:
created the path $PYENV_ROOT/plugins/*/etc/pyenv.d
cat /usr/local/opt/pyenv/plugins/pyenv-virtualenv/etc/pyenv.d/exec/virtualenv.bash
after_virtualenv 'echo after: Dani'
However when i create a virtualenv i get the expected error
pyenv virtualenv 2.7.8 dani2
[pyenv-exec:39] for script in '"${scripts[@]}"'
+ [pyenv-exec:40] source /usr/local/opt/pyenv/plugins/pyenv-virtualenv/etc/pyenv.d/exec/virtualenv.bash
++ [virtualenv.bash:1] after_virtualenv 'echo after: Dani'
/usr/local/opt/pyenv/plugins/pyenv-virtualenv/etc/pyenv.d/exec/virtualenv.bash: line 1: after_virtualenv: command not found
Any idea what am i missing?
I've looked up at your test and i can't see how your tests succeed.
@test "pyenv-virtualenv hooks" {
cat > "${HOOK_PATH}/virtualenv.bash" <<OUT
before_virtualenv 'echo before: \$VIRTUALENV_PATH'
after_virtualenv 'echo after: \$STATUS'
OUT
stub pyenv-prefix "echo '${PYENV_ROOT}/versions/3.2.1'"
stub pyenv-prefix "echo '${PYENV_ROOT}/versions/3.2.1'"
stub pyenv-prefix "echo '${PYENV_ROOT}/versions/3.2.1'"
stub pyenv-hooks "virtualenv : echo '$HOOK_PATH'/virtualenv.bash"
stub pyenv-exec "echo PYENV_VERSION=3.2.1 \"\$@\""
stub pyenv-rehash "echo rehashed"
Have you loaded any other plugin apart from default IFS=$'\n' scripts=(``pyenv-hooks virtualenv``)
?
Cheers,
Dani
from pyenv-virtualenv.
Okay however in this case the notes are not up to date, correct? Because i set it up for step 6).
Hooks are bash scripts named like HOOK_NAME/*.bash, where "HOOK_NAME" is one of:
exec
rehash
which
Hooks are looked for in $PYENV_HOOK_PATH, which is composed of:
1. $PYENV_HOOK_PATH (external value)
2. $PYENV_ROOT/pyenv.d
3. /usr/local/etc/pyenv.d
4. /etc/pyenv.d
5. /usr/lib/pyenv/hooks
6. $PYENV_ROOT/plugins/*/etc/pyenv.d
from pyenv-virtualenv.
Umm. Sorry for complication.
By default, pyenv
itself provides hooks for exec
, rehash
and which
. In pyenv-virtualenv
, it also provides hooks for virtualenv
in addition to pyenv
's hooks. Because pyenv-virtualenv
is an individual project from pyenv
, the hook of pyenv-virtualenv
was not described in the wiki of pyenv
.
I don't think it's outdated. But complicated :(
from pyenv-virtualenv.
Fyi i confirm following your suggestion everything works as expected.
Many thanks!
P.S - will be good if we can can make the notes a bit more clear
from pyenv-virtualenv.
@DanyC97 I'd also like to install a standard set of packages in new virtualenvs. Any chance you could post your hook file? I'm having issues getting it to work (specifically, how do I reference pip in the newly created virtualenv from the script?). Cheers.
from pyenv-virtualenv.
I am trying to do the same thing. Doing an after_virtualenv 'echo hi'
works. However, when I try to pip install it doesn't really install anything. Basically, I want a set of packages to be installed with every virtualenv created. Is that possible?
from pyenv-virtualenv.
@robcowie @nayefc Are you looking for something similar to rbenv-default-gems
, but for pyenv
? If so, I'm thinking about writing a pyenv-default-pips
plugin that should take care of this.
from pyenv-virtualenv.
I'm unfamiliar with that project but it certainly looks like what I want. If you start the project, let me know. Cheers.
from pyenv-virtualenv.
@jawshooah Yup exactly. For example, I need pylint and Jedi and jediepcserver installed for each virtualenv and I was hoping to automate that as part of the pyenv mode hooks.
from pyenv-virtualenv.
Just forked rbenv-default-gems
, working on it now.
from pyenv-virtualenv.
@jawshooah That would be amazing please keep me posted!
from pyenv-virtualenv.
Boom.
from pyenv-virtualenv.
You're a legend. I'll give it a go shortly and report back.
from pyenv-virtualenv.
@jawshooah I'm trying to modify this to do it as I create a virtualenv, not when I install a version. I changed after_install to after_virtualenv but I still can't see the packages when I do pip freeze. Any ideas how to do such a modification?
from pyenv-virtualenv.
Ah, seems I misunderstood the problem. The plugin is meant to install default packages when you install a new Python version; I assumed that if you wanted default packages for virtualenvs, the simplest way to get them was to have default packages for the Python base.
The reason after_virtualenv
doesn't work here is that the plugin itself runs as an after_install
hook. I could add a duplicate of default-packages.bash
to etc/pyenv.d/virtualenv
and sed 's/after_install/after_virtualenv/'
, but it may be better to just create a separate pyenv-virtualenv-default-packages
plugin.
from pyenv-virtualenv.
Turns out pyenv-virtualenv
does not include packages in the base Python when creating a virtualenv, which is probably expected behavior, so my initial thinking was flawed from the start. I'll make the change.
from pyenv-virtualenv.
@jawshooah That's fine I can do it myself. How do I create a plugin that runs after a virtualenv is created? I don't see where in your code you explicitly make an "after_install" package except for saying "after_install" in the bash script.
from pyenv-virtualenv.
Until I make the change upstream, you can just copy etc/pyenv.d/install/default-packages.bash
to etc/pyenv.d/virtualenv/
and change after_install
to after_virtualenv
and PYENV_VERSION
to VIRTUALENV_NAME
in the new file. Haven't tried it yet myself, but it should work.
Edit: Sorry, change VERSION_NAME
to VIRTUALENV_NAME
.
from pyenv-virtualenv.
I created an issue for this on my repo if you'd like to continue the conversation over there.
from pyenv-virtualenv.
For those coming here from Google that want to install and/or upgrade packages after creation of a new virtualenv, you can do so as follows:
Run the following commands:
mkdir -p "$(pyenv root)/pyenv.d/virtualenv" # this will create a directory to hold "hooks" for pyenv virtualenv
$EDITOR "$(pyenv root)/pyenv.d/virtualenv/after.bash" # open your favorite editor to edit a new hook script
In your newly opened editor add the following contents to after.bash:
after_virtualenv 'PYENV_VERSION="$VIRTUALENV_NAME" pyenv-exec pip install --upgrade pip setuptools wheel'
And you're done! Now any time you create a new virtualenv, it will upgrade pip, setuptools and wheel and/or install them.
If you want to install (for example) jupyter
to each new virtualenv, you can just add it at the end of the above command
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.