I have pyenv installed and my .zshenv looks like the following :
export PYENV_ROOT="$HOME"/.pyenv
export PATH="$PYENV_ROOT"/bin:"$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
eval "$(pyenv virtualenv-init -)"
When I open a new terminal it gives me the following error:
.zshenv. command not found: : pyenv
The fix in the github issue link didn't work for me.
The problem was that pyenv wasn't on the path at the time of running pyenv init.
I add export PATH=/usr/local/bin:"$PATH" to my .zshenv before calling pyenv init.
Related
I am working on a Macbook Pro running MacOS Monterrey, and I'm following instructions to work in a virtual environment from this site. https://duncanleung.com/set-up-python-pyenv-virtualenv-poetry/
While I am able to create a virtualenv, I am unable to activate it.
On running pyenv activate my-env, I get this error message:
Failed to activate virtualenv.
Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.
My zshrc file has this content:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv virtualenv-init -)"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
PATH=$(pyenv root)/shims:$PATH
Result of which python:
/Users/abc/.pyenv/shims/python
Result of python -V: Python 3.9.9
What could be possible reasons for the virtualenv not activating?
This is only partly related to #1737
I have just upgraded to the new MAC OS BigSur.
I have installed XCode Beta 12.3 and configured it with Command Line Tools 12.3 beta.
If I do:
$ CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" pyenv install --patch 3.8.0 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
as per the instructions of this blog: https://dev.to/kojikanao/install-python-3-8-0-via-pyenv-on-bigsur-4oee It works.
However, I started using pyenv after finding a very attractive way of managing many python envs through automatic activation as described in this blog: https://glhuilli.github.io/virtual-environments.html
Since I upgraded, I have not been able to get this to work.
Questions:
When I cd into a directory with .python-version and
.python-virtualenv, the script prompts me to create a new env with
pyenv install. This fails with the ./Modules/pwdmodule.c error. How
can I alter the above script in order to create an environment using
.python-version and .python-virtualenv? I can obviously provide a
different python version in the script, but what about the name of
the virtual environment? How can I include that?
I want the new
virtual environment contents to be located in the directory where
pyenv is called and not /Users/username/.pyenv. How can this be
done? i am sure others are facing similar issues. Will these be
fixed eventually? Ideally, I would like to be able to just do pyenv
install and be done...
Thanks in advance.
So, about question 1: The answer is that pyenv install will not work at the momment. However, as long as the required pyenv version is installed, the script will work like a charm. So you will have to install it in a different way (not with pyenv install).
Example:
Suppose you are given two files:
.python-vesion
.python-virtualenv
respectively encapsulating: 3.8.2 and test-venv. Then just run:
CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include"
LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib"
pyenv install --patch \$(head -n 1 .python-version) < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
This should successfully install a pyenv for 3.8.2.
Then just do:
pyenv virtualenv \$(head -n 1 .python-virtualenv)
Then if you run:
\$ pyenv virtualenvs
3.8.2/envs/test-venv (created from /Users/{your-pc-name}/.pyenv/versions/3.8.2)
test-venv (created from /Users/{your-pc-name}/.pyenv/versions/3.8.2)
you will confirm that the new env has been created.
About question 2: Here is the updated script:
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
# Automatic venv activation
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
# Undo any existing alias for `cd`
unalias cd 2>/dev/null
# Method that verifies all requirements and activates the virtualenv
hasAndSetVirtualenv() {
# .python-version is mandatory for .python-virtualenv but not vice versa
if [ -f .python-virtualenv ]; then
if [ ! -f .python-version ]; then
echo "To use .python-virtualenv you need a .python-version"
return 1
fi
fi
# Check if pyenv has the Python version needed.
# If not (or pyenv not available) exit with code 1 and the respective instructions.
if [ -f .python-version ]; then
if [ -z "`which pyenv`" ]; then
echo "Install pyenv see https://github.com/yyuu/pyenv"
return 1
elif [ -n "`pyenv versions 2>&1 | grep 'not installed'`" ]; then
# Message "not installed" is automatically generated by `pyenv versions`
echo 'run "pyenv install"'
return 1
fi
fi
# Create and activate the virtualenv if all conditions above are successful
# Also, if virtualenv is already created, then just activate it.
if [ -f .python-virtualenv ]; then
VIRTUALENV_NAME="`cat .python-virtualenv`"
PYTHON_VERSION="`cat .python-version`"
MY_ENV=$PYENV_ROOT/versions/$PYTHON_VERSION/envs/$VIRTUALENV_NAME
([ -d $MY_ENV ] || virtualenv $MY_ENV -p `which python`) && \
source $MY_ENV/bin/activate
fi
}
pythonVirtualenvCd () {
# move to a folder + run the pyenv + virtualenv script
cd "$#" && hasAndSetVirtualenv
}
# Every time you move to a folder, run the pyenv + virtualenv script
alias cd="pythonVirtualenvCd"
I have some problems about pyenv in my MAC so I removed it.
After that I open the terminal, always -bash: pyenv: command not found message appear.
I guess this is about environment problem.
How can I solve this?
Last login: Wed Jun 19 22:15:19 on ttys000
-bash: pyenv: command not found
-bash: pyenv: command not found
-bash: pyenv: command not found
-bash: pyenv: command not found
-bash: pyenv: command not found
-bash: pyenv: command not found
-bash: pyenv: command not found
ShinTaeyongui-iMac:~ shintaeyong$
A configuration file of your shell (bash) still contains a reference to the pyenv command. Depending on how you installed pyenv, this configuration file could be ~/.bashrc or ~/.bash_profile (or both).
The lines you are looking for are probably either (if installed via pipenv-installer):
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Or (if installed via the manual instructions):
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
You should be able to safely remove all lines containing pipenv. If you want to be safe, you can disable the lines instead of removing them by adding an # in front of them.
I'm running into an issue installing a package that's reliant on ocamlfind but I'm getting an ocamlfind: command not found error when making.
I have installed ocamlfind with the ocaml package manager and have tried reinstalling using "opam reinstall ocamlfind".
I have also tried the 'eval opam config env' command to see if updates my bin.
Has anyone run into a similar issue/know what this might be caused by
The output when running the make:
make
ocamlfind ocamlc -pp "camlp4o -I lib/dcg -I lib/ipp pa_dcg.cmo pa_ipp.cmo" -w usy -thread -I lib -I lib/dcg -I lib/ipp -c semantics.ml
/bin/sh: ocamlfind: command not found
The output when trying ocamlfind
ocamlfind
-bash: ocamlfind: command not found
ocaml is installed
opam install ocamlfind
[NOTE] Package ocamlfind is already installed (current version is 1.5.5).
and when running the eval command
eval 'opam config env'
CAML_LD_LIBRARY_PATH="/home/centos/.opam/system/lib/stublibs:/usr/lib64/ocaml/stub libs"; export CAML_LD_LIBRARY_PATH;
MANPATH="/home/centos/.opam/system/man:"; export MANPATH;
PERL5LIB="/home/centos/.opam/system/lib/perl5"; export PERL5LIB;
OCAML_TOPLEVEL_PATH="/home/centos/.opam/system/lib/toplevel"; export OCAML_TOPLEVEL_PATH;
PATH="/home/centos/.opam/system/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin"; export PATH;
I'm on a server running centos 7
This command
eval 'opam config env'
is almost assuredly a typo and was supposed to be
eval `opam config env`
though using $(...) instead is the modern equivalent and avoids this font-fact confusion
eval $(opam config env)
That being said that just sets the environment variables in the current shell session (and exports them for use by processes run by this shell session).
As such that needs to be run in every shell session that needs those set (including each line of the makefile that expects them to be set if the environment that runs make doesn't already have them set and exported).
try
sudo apt-get install ocaml-findlib
Something strange and unexpected is happening with the sys.path of any virtual environment I set. For example, a clean env:
$ virtualenv test
$ source test/bin/activate
(test) $
This is the expected PYTHONPATH:
(test) $ python
>>> import sys
>>> print '\n'.join(sys.path)
/home/user/test/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/home/user/test/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg
/home/user/test/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/home/user/test/lib/python2.7/site-packages/pip-1.1-py2.7.egg
/home/user/test/lib/python2.7
/home/user/test/lib/python2.7/plat-linux2
/home/user/test/lib/python2.7/lib-tk
/home/user/test/lib/python2.7/lib-old
/home/user/test/lib/python2.7/lib-dynload
/usr/lib/python2.7
/usr/lib/python2.7/plat-linux2
/usr/lib/python2.7/lib-tk
/home/user/test/local/lib/python2.7/site-packages
/home/user/test/lib/python2.7/site-packages
But this is the one I really get:
(test) $ bpython
>>> import sys
>>> print '\n'.join(sys.path)
/usr/bin
/usr/lib/python2.7
/usr/lib/python2.7/plat-linux2
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
I can't figure out the reason of the two different sys.paths.
Because of that, no pip installation works!
I'm using Virtualenv 1.7.2, Ubuntu 12.04, Python 2.7.3.
Any help will be appreciated.
Rather than installing one copy of bpython per virtualenv, I've added this function to my shell profile (for example ~/.bashrc or ~/.zshrc). It wraps the bpython command with some logic to load the virtual environment's python path (if you have an active virtual environment).
bpython() {
if test -n "$VIRTUAL_ENV"
then
PYTHONPATH="$(python -c 'import sys; print ":".join(sys.path)')" \
command bpython "$#"
else
command bpython "$#"
fi
}
I found that I needed to deactivate and reactivate my virtualenv after installing bpython for it to work.
pip install bpython
deactivate
. bin/activate # or your equivalent activation command
My hypothesis is that you have not installed bpython after you have activated the new virtualenv.
I followed it up exactly like you mentioned:
mkvirtualenv bpython
(bpython)~ $ pip install bpython
(bpython)~ $bpython
and then ran the commands:
>>> import sys
>>> print '\n'.join(sys.path)
/Users/xxxx/.virtualenvs/bpython/bin
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/site-packages/pip-1.1-py2.7.egg
/Users/xxxx/.virtualenvs/bpython/lib/python27.zip
/Users/xxxx/.virtualenvs/bpython/lib/python2.7
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/plat-darwin
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/plat-mac
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/plat-mac/lib-scriptpackages
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/lib-tk
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/lib-old
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/lib-dynload
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/site-packages
and did the same thing again by running python under the activated virtualenv
(bpython)~ $ python
.....
>>> import sys
>>> print '\n'.join(sys.path)
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/site-packages/pip-1.1-py2.7.egg
/Users/xxxx/.virtualenvs/bpython/lib/python27.zip
/Users/xxxx/.virtualenvs/bpython/lib/python2.7
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/plat-darwin
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/plat-mac
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/plat-mac/lib-scriptpackages
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/lib-tk
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/lib-old
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/lib-dynload
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/site-packages
I saw no difference in the two results
I also discovered that if you have bpython installed locally, you need to create your virtualenv with --no-site-packages for it to work properly. If you created your virtualenv without that flag, you can create an empty file named no-global-site-packages.txt in ~/.virtualenvs/<env-name>/lib/python2.7/ as noted in this Stack Exchange answer.