question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

envdir not working with pyenv + virtualenvs properly? daemontools behaves correctly

See original GitHub issue

hi @jezdez, it seems envdir is modifying the PATH in some unexpected way when using virtualenv. daemontools seems to be working as expected.

I have a pretty vanilla set up using pyenv and virtualenvwrapper. Nothing fancy.

setup:

$ deactivate
$ mkvirtualenv test
$ deactivate

with jezdez/envdir:

$ workon test
$ which python
/Users/johria/.virtualenvs/test/bin/python
$ envdir envs/prod which python
/Users/johria/.pyenv/versions/3.6.1/bin/python

^^^^ error is here ^^^^

uninstall jezdez/envdir, install daemontools:

$ deactivate
$ pip uninstall envdir
$ brew install daemontools

with daemontools:

$ workon test
$ which python
/Users/johria/.virtualenvs/test/bin/python
$ /usr/local/bin/envdir envs/prod which python
/Users/johria/.virtualenvs/test/bin/python

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
AlJohricommented, Jun 22, 2017

This only occurs with pyenv. With homebrew python:

$ echo "$PATH"
bin:/usr/local/sbin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
$ python -c "import os; print(os.environ['PATH'])"
bin:/usr/local/sbin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin

No changes to the PATH. The pyenv wrapper shim is doing the addition to the PATH!

screen shot 2017-06-21 at 9 09 38 pm

SO. In conclusion, when envdir is installed globally via pyenv, the pyenv shim is injecting variables on to the PATH. When inside a virtualenv, the shimmed envdir ends up changing the PATH so its no longer using the virtualenv but instead its using the global python.

Workaround: Install envdir using homebrew python or inside of your virtualenv. Do not install envdir via pyenv because it will change the PATH.

1reaction
blueyedcommented, Mar 21, 2019

@hangtwenty Just a quick side offtopic note, I am using the following shell function to export envdirs (zsh):

envdir-export () {
	setopt extendedglob
	local envdir=$1 
	if ! [ -d "$envdir" ]
	then
		echo "$envdir is not a dir."
		return 1
	fi
	for i in $envdir/*(.)
	do
		if [[ "${i:t}" == *.* ]]
		then
			continue
		fi
		echo "Exporting $i:t"
		eval "export ${i:t}='$(<$i)'"
	done
}

I call this for example via autoenv (https://github.com/Tarrasch/zsh-autoenv) for projects, or manually on certain dirs to get extra parts of some config.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues with pyenv-virtualenv: Python and PIP not changed ...
It turns out that in order to automatically activate / deactivate a venv when entering / leaving a directory the .python-version file in ......
Read more >
Venv Envy (A Guide to Python Virtual Environments) - Medium
pyenv documentation; installation problems; virtual environment problems; uninstall pyenv, pyenv-virtualenv, and Homebrew; what's next ...
Read more >
How to Manage your Python Projects with Pipenv and Pyenv
Many combinations of compatibility issues can be found but by having those isolated environments ... You have installed Pyenv successfully.
Read more >
envdir - bytemeta
envdir not working with pyenv + virtualenvs properly? daemontools behaves correctly. jezdez. jezdez OPEN · Updated 5 years ago ...
Read more >
Using pyenv and pyenv-virtualenv to install Python and create ...
To manage my Python versions I'm using using pyenv and pyenv-virtualenv and once they are correctly configured, it's very easy to install a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found