If I attempt to create a virtual env I get this error message, which I do not understand: bad interpreter: No such file or directory. I have reviewed this stack overflow answer and have tried to apply it in the diagnostic steps below.
This is my first day running on Mojave but I don't know if that is a factor in this issue or not.
I have created a new empty folder for the project at /Users/Wes/Dropbox/Programming/Python/glade_againn
My plan has been to run the project in the virtualenv /Users/Wes/.virtualenvs/glade_againn
However, when I attempt to use virtualenv I get this error message.
$ virtualenv --version
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory
If I attempt to install virtualenv with PIP I am told it already exists.
$ pip install virtualenv
Requirement already satisfied: virtualenv in /usr/local/lib/python2.7/site-packages (15.2.0)
$
My current PATH is
echo $PATH
/Library/Frameworks/Python.framework/Versions/3.6/bin:/opt/local/bin:/opt/local/sbin:/usr/local/opt/postgresql#9.4/bin:/usr/local/Cellar/postgresql/9.5.4_1/bin/psql/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS:/usr/local/git/bin:/Users/Wes/bin:/sw/bin:/usr/local/bin:/Users/Wes/.sdkman/candidates/groovy/current/bin/
If you search for pyth* across all those directories you get this list, in this order.
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3-config
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6-config
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m-config
/opt/local/bin/python2.7
/opt/local/bin/python2.7-config
/opt/local/bin/python3.4
/opt/local/bin/python3.4-config
/opt/local/bin/python3.4m
/opt/local/bin/python3.4m-config
/opt/local/bin/pythonw2.7
/usr/local/bin/python-32
/usr/local/bin/python2-32
/usr/local/bin/python2.7-32
/usr/local/bin/python3
/usr/local/bin/python3-config
/usr/local/bin/python3.6
/usr/local/bin/python3.6-config
/usr/local/bin/python3.6m
/usr/local/bin/python3.6m-config
/usr/local/bin/pythoni
/usr/local/bin/pythoni1
/usr/local/bin/pythonw-32
/usr/local/bin/pythonw2-32
/usr/local/bin/pythonw2.7-32
/usr/bin/python
/usr/bin/python-config
/usr/bin/python2.7
/usr/bin/python2.7-config
/usr/bin/pythonw
/usr/bin/pythonw2.7
/sw/bin/python2.7
/sw/bin/python2.7-config
/usr/local/bin/python-32
/usr/local/bin/python2-32
/usr/local/bin/python2.7-32
/usr/local/bin/python3
/usr/local/bin/python3-config
/usr/local/bin/python3.6
/usr/local/bin/python3.6-config
/usr/local/bin/python3.6m
/usr/local/bin/python3.6m-config
/usr/local/bin/pythoni
/usr/local/bin/pythoni1
/usr/local/bin/pythonw-32
/usr/local/bin/pythonw2-32
/usr/local/bin/pythonw2.7-32
Does anyone have a suggestion on how to get virtualenv to work again?
Try to reinstall using this
pip install -U --force-reinstall virtualenv
if above solution doesn't work for you
you should create a new virtualenv again because of mojave update
In my case I was renaming project and project's folder where venv has been located.
So in my case I was changing paths to python interpreter in the following files:
~/PycharmProjects/myproject/venv/bin/activate*
And modified ~/PycharmProjects/myproject/venv/bin/pip* files to:
#!/home/myuser/PycharmProjects/myproject/venv/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
To modify it I was required to login with root permissions: sudo su. The sudo vim.tiny venv/bin/pip just not allowed me to edit the files.
I've changed only the first line starting with #!/home...
In my case, I was on MacOS and I had python3.9 installed, but virtualenv was installed using python3.7 and at some point I uninstalled python3.7.
$ /usr/local/bin/virtualenv --version
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python3.7: bad interpreter: No such file or directory
However, my python version:
$ which python3.9
/usr/local/bin/python3.9
No amount of pip or pip3 install/uninstall/install virtualenv worked for me.
Finally I did the following:
$ python3.9 -m pip install --user virtualenv
Collecting virtualenv
Using cached virtualenv-20.4.6-py2.py3-none-any.whl (7.2 MB)
<snip>
Successfully installed appdirs-1.4.4 distlib-0.3.1 filelock-3.0.12 virtualenv-20.4.6
And then
$ /usr/local/bin/virtualenv --version
virtualenv 20.4.6 from <mypath>
Yay!!
That solved the problem in my case: (my env file is called .venv)
mv .venv .venv_old
python3.7 -m venv .venv
source .venv/bin/activate
pip install wheel
pip install --upgrade pip wheel setuptools
pip install -r requirements.txt
In my case, the error shows in Github action and the root cause is the broken python symbolic link. As a workaround, I just simply re-create it during the process.
Error:
home/runner/work/_temp/810926a2-36c5-4488-ac84-6f3f57713147.sh: /home/runner/work/dataops/dataops/.venv/bin/pytest: /home/runner/work/dataops/dataops/.venv/bin/python: bad interpreter: No such file or directory
Root Cause:
/home/runner/work/dataops/dataops/.venv/bin/python: broken symbolic link to /opt/hostedtoolcache/Python/3.9.15/x64/bin/python3.9
Solution:
Add below scripts into wherever has broken link:
PYTHON_PATH=$(which python3)
source .venv/bin/activate
PYTHON_BROKEN_PATH=$(dirname $(which pip))
rm $PYTHON_BROKEN_PATH/python
ln -s $PYTHON_PATH $PYTHON_BROKEN_PATH/python
export PATH=$PATH:$(dirname $PYTHON_BROKEN_PATH)
Similar problem after switching package managers on a Mac. No reinstallation required for my use case, just updates to 2 files.
1st update config file
I updated pyvenv.cfg in the virtual environment directory (cd /to/your/venv/dir)
I had to update the home and the version settings.
home = /usr/local/bin
include-system-site-packages = false
version = 3.10.8
2nd fix symlinks
Lastly I updated the symlink to the python executable. It's in the virtual environment's bin directory.
cd /to/your/venv/dir/bin
ln -s /usr/local/bin/python3.10 python
Note, in my case there were 2 other symlinks to python executables in the venv/bin directory, python3 and python3.10. I didn't need to touch these as they were both pointers to the python symlink that was just updated.
Related
I would like to use virtualenvwrapper with Python 3.6, however, I am working on a Mac which defaults to using Python 2.7 and I am having issues. Here's what I have done so far. Using the following commands, I have found the locations of where each Python version is saved:
>> which python
>> /usr/bin/python
>> which python3
>> /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
I have successfully installed virtualenv and virtualenvwrapper using:
>> pip3 install virtualenv
>> pip3 install virtualenvwrapper
I then search for the location of virtualenv and virtualenv wrapper to confirm their locations:
>> pip3 show virtualenv
>> Location: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
>> pip3 show virtualenvwrapper
>> Location: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
If I go to this site-packages directory there is the following:
virtualenvwrapper
|--- __pycache__
|--- hook_loader.py
|--- project.py
|--- user_scripts.py
virtualenvwrapper-4.8.2-py2.7-nspkg.pth
virtualenvwrapper-4.8.2.dist-info
According to virtualenvwrapper's documentation, I should add the following to my shell startup file to ensure initialization, changing virtualenvwrapper's path to the one set on my machine:
export WORKON_HOME=~/Envs
$ mkdir -p $WORKON_HOME
$ source /usr/local/bin/virtualenvwrapper.sh
I then searched for where virtualenvwrapper.sh is actually located (for some reason, it is not located where the virtualenvwrapper module is installed):
>> which virtualenvwrapper.sh
>> /Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenvwrapper.sh
I changed my .bashrc file using:
>> nano ~./bashrc
Copied in the following:
# script for virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenvwrapper.sh
I then opened up a new terminal and ran:
>> source `which virtualenvwrapper.sh`
Which gave me:
/usr/bin/python3: No such file or directory
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 and that PATH is
set properly.
What I don't understand is why virtualenvwrapper needs to be located at /usr/bin/python3 which is not a directory. Since it is in bin, it is also impossible for me to make it a directory. Additionally, the virtualenvwrapper.hook_loader is not where virtualenvwrapper.sh is which I think may be causing an issue.
I also tried creating a symbolic link to /usr/local/bin because some people stated that it solved their issue but this didn't solve mine:
sudo ln /Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenvwrapper.sh /usr/local/bin/virtualenvwrapper.sh
Another issue altogether is whether or not I need to install it using pip3 if I want to use virtualenvwrapper for Python3. For example, this post states that you only need to pass a flag, however, you should also be wary of installing it on your base Python installation.
Add
export VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
to .bashrc and execute the command in the terminal. That sets the path to Python interpreter for virtualenvwrapper.
I've been keeping all my python2.7 installs in my ~/.local/ directory that way I don't have to sudo every time I want to do a pip install. I also have $HOME/.local/lib/python2.7/site-packages on my $PYTHONPATH. This has worked well for years but now I find myself needing to run python3 programs more frequently. After much research it seems like virtualenv is the most recommended way to deal with python 2 and 3 on the same system. But I am running into troubles. I can spin up a python3 virtual environment but when I try to install new libs with pip, my old global path (i.e. ~/.local/) is still being searched by pip, which makes sense. However, this is even the case if I remove my ~/.local/bin/ directory from my $PATH and unset my $PYTHONPATH.
Here is are the steps I took:
First check the preliminaries before activating virtualenv. (I'm on Ubuntu 16.04 btw)
maddoxw#firefly:~$ echo $PATH
/usr/local/cuda-8.0/bin:/home/maddoxw/.node_modules_global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/maddoxw/bin:/home/maddoxw/scripts
maddoxw#firefly:~$ echo $PYTHONPATH
maddoxw#firefly:~$ python --version
Python 2.7.12
maddoxw#firefly:~$ python3 --version
Python 3.5.2
maddoxw#firefly:~$ which pip
Since I removed my ~/.local/bin directory from my path, then I can be certain pip will not be found. Also, $PYTHONPATH is still empty. Now I create my virtualenv:
maddoxw#firefly:~$ mkdir test && cd test/
mkdir: created directory 'test'
maddoxw#firefly:~/test$ python3 -m venv .env
maddoxw#firefly:~/test$ source .env/bin/activate
(.env) maddoxw#firefly:~/test$ echo $PATH
/home/maddoxw/test/.env/bin:/usr/local/cuda-8.0/bin:/home/maddoxw/.node_modules_global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/maddoxw/bin:/home/maddoxw/scripts
(.env) maddoxw#firefly:~/test$ echo $PYTHONPATH
(.env) maddoxw#firefly:~/test$ which python
/home/maddoxw/test/.env/bin/python
(.env) maddoxw#firefly:~/test$ python --version
Python 3.5.2
(.env) maddoxw#firefly:~/test$ which pip
/home/maddoxw/test/.env/bin/pip
Good. My ~/.local/ is still NOT on my $PATH, $PYTHONPATH is still empty, python points to the correct path and version, and pip is pointing to the correct location. Now lets try to pip install a fresh lib.
(.env) maddoxw#firefly:~/test$ pip install Cython
Requirement already satisfied: Cython in /home/maddoxw/.local/lib/python2.7/site-packages
Why is pip still looking in a non-$PATH path?
First, install pip3 to use with python3. You can install it with the following command and then use pip3 to install your packages.
sudo apt-get install python3-pip
[Solved]
When I initially set up my python2.7 environment way back when, I created for myself a handy little function wrapper around pip so that I wouldn't have to type out the --user every time I wanted to pip install
pip() {
if [ "$1" = "install" -o "$1" = "bundle" ]; then
cmd="$1"
shift
$HOME/.local/bin/pip $cmd --user $#
else
$HOME/.local/bin/pip $#
fi
}
I put this function in ~/.bash.d/bash_functions
and in my ~/.bashrc i added the line,
[ -f ~/.bash.d/bash_functions ] && source ~/.bash.d/bash_functions
So, although I removed $HOME/.local/ from my path. This wrapper function was still being called everytime I fired up a new terminal. Weather or not I was or was not in a virtualenv was irrelevant.
Solution?
Commented out (or delete completely) the function wrapper fixed it.
I am new in centos.I am try to do an application on it.For my application I need to install python 2.7.But the default one on server was python 2.6. So tried to upgrade the version .And accidentally I deleted the folder /usr/bin/python.After that I Installed python 2.7 through make install.I created the folder again /usr/bin/python and run command sudo ln -s /usr/bin/python2.7 /usr/bin/python. After this when I tried to run YUM commands I am getting the error
-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: Permission denied
drwxrwxrwx 2 root root 4096 Mar 8 00:19 python
this is permission showing for the directory /usr/bin/python
CentOS requires that /usr/bin/python be pointed to Python 2.6, not any other version. Run the following commands:
sudo rm -rf /usr/bin/python
sudo ln -s /usr/bin/python2.6 /usr/bin/python
to at least fix that part of it. Next time you're building Python, use the defaults and install it to /usr/local/bin, not /usr/bin. That's what the /usr/local hierarchy is for - user-installed programs. /usr and /usr/bin should only be for system-installed programs (such as those installed by yum or its graphical equivalents), and you should keep out unless you know what you're doing. To use identically-named programs in /usr/local/bin instead of their counterparts in /usr/bin, open your ~/.bashrc or ~/.bash_profile (whichever your system uses) and add the following as the last line:
export PATH=/usr/local/bin:$PATH
Restart your shell session, and you should be all set.
yum doesn't work with python2.7.
You should do the following
vim /usr/bin/yum
change
#!/usr/bin/python
to
#!/usr/bin/python2.6
If your python2.6 was deleted, then reinstall them and point the directory in /usr/bin/yum to your python2.6 directory.
It is very simple; because the Python package was removed, the yum command won't work.
Please use below link to install packages:
Go to Link and download python package
wget http://mirror.centos.org/centos/7/sclo/x86_64/rh/python27/python27-1.1-26.1.el7.x86_64.rpm
rpm -ivh python27-1.1-26.1.el7.x86_64.rpm
Then yum will work.
this problem is that yum file start head write #!/usr/local/bin/python2.6, write binary file, is not dir, is python binary file
Resolution for CentOs 7:
dnf reinstall python-2.7.5-92.el7_9.x86_64
dnf reinstall yum
Remove python3 first using dnf if it is installed already.
-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: Permission denied then
first remove python follow command line
-- sudo rpm -e python
second check which package install this command line
-- sudo rpm -q python
then install package
-- sudo yum install python*
i think this problem solve
I've been trying to get up and running with the built-in "venv" module of Python 3.3 on my OS X machine. I've installed Python 3.3 using Homebrew.
As per the docs, creating and switching virtual environment works as you'd expect:
$ python3 -m venv myvenv
$ source myvenv/bin/activate
And I've tested something like this:
$ echo "YEAH = 'YEAH!'" > myvenv/lib/python3.3/site-packages/thingy.py
$ python
>>> import thingy
>>> print(thingy.YEAH)
'YEAH!'
But when I try to install distribute, it simply won't go in the proper place. For some reason, it insists on trying to install into /usr/local/lib/python3.3/site-packages/, which fails with the following messages:
No setuptools distribution found
running install
Checking .pth file support in /usr/local/lib/python3.3/site-packages/
/Users/victor/myvenv/bin/python -E -c pass
TEST FAILED: /usr/local/lib/python3.3/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/usr/local/lib/python3.3/site-packages/
and your PYTHONPATH environment variable currently contains:
''
This happens regardless if I try to install using distribute_setup.py or using the source distribution directly. I've even tried using --prefix=/Users/victor/myenv but it still tries to put everything in my "global" site-packages.
I can't figure out why this happens, but it's consistent on two of my machines. Note that sys.prefix reports the correct path (the virtual environment).
Is this a problem with Homebrew? OS X? Python 3.3? venv? Me?
This has been an issue with Homebrew, yes, but it is working now since https://github.com/mxcl/homebrew/commit/0b50110107ea2998e65011ec31ce45931b446dab.
$ brew update
$ brew rm python3 #if you have installed it before
$ brew install python3
$ cd /tmp
$ which python3
/usr/local/bin/python3
$ python3 -m venv myvenv
$ source myvenv/bin/activate
$ wget http://python-distribute.org/distribute_setup.py # may need brew install wget
$ python3 distribute_setup.py
...
Finished processing dependencies for distribute==0.6.45
After install bootstrap.
Creating /private/tmp/myvenv/lib/python3.3/site-packages/setuptools-0.6c11-py3.3.egg-info
Creating /private/tmp/myvenv/lib/python3.3/site-packages/setuptools.pth
You see that distribute install successfully into the /tmp dir.
This happens because homebrew installs distutils config file:
$ brew cat python3 | grep "Tell distutils" -A5
# Tell distutils-based installers where to put scripts
(prefix/"Frameworks/Python.framework/Versions/#{VER}/lib/python#{VER}/distutils/distutils.cfg").write <<-EOF.undent
[install]
install-scripts=#{scripts_folder}
install-lib=#{site_packages}
EOF
$ mv ~/.local/Frameworks/Python.framework/Versions/3.3/lib/python3.3/distutils/distutils.cfg ~/tmp/
$ cat ~/tmp/distutils.cfg
[install]
install-scripts=/Users/gatto/.local/share/python3
install-lib=/Users/gatto/.local/lib/python3.3/site-packages
$ . venv/bin/activate
(venv) $ python distribute-0.6.36/distribute_setup.py
(venv) $ ls venv/lib/python3.3/site-packages/
distribute-0.6.36-py3.3.egg easy-install.pth setuptools-0.6c11-py3.3.egg-info setuptools.pth
See "distutils.cfg Can Break venv" issue at bugs.python.org.
I am trying to activate my Virtual Python Environment to use with Pylons but I think I am executing the commands wrong.
jem#jem-laptop:~$ source env/bin/activate
bash: env/bin/activate: No such file or directory
What am I doing wrong?
How should I do it right?
I realize I had to do
jem#jem-laptop:~$ ls
Desktop examples.desktop Public shortener.rb
Documents Mac4Lin_v1.0 ruby-1.9.1-p378 Templates
Downloads Music rubygems-1.3.7 Videos
Dropbox Pictures setcolors.vim virtualenv.py
And here we see virtualenv.py. From here I just had to
jem#jem-laptop:~$ virtualenv ENV
New python executable in ENV/bin/python
Installing setuptools............done.
And then
jem#jem-laptop:~$ source ENV/bin/activate
(ENV)jem#jem-laptop:~$ deactivate
jem#jem-laptop:~$
Solved :)
I usually do it this way:
$ cd the_project_dir
$ . bin/activate
(the_project)$ _
I need to be in the project directory anyway to go on with the work.
Obviously the_project_dir is the name of a directory where you have created a virtualenv.
In 2.7 version I used this command:
$ cd project_name
$ virtualenv venv --distribute
$ source venv/Scripts/activate
(venv)
I would recommend using virtualenvwrapper. It makes working with virtualenv a lot simpler, especially if you have more than one virtualenv.
Simple fix:
$ virtualenv env
$ cd env/Scripts/
$ . activate
On FreeBSD I solved this doing following:
# ls mypienv
# mypienv/bin/activate
mypienv/bin/activate: Permission denied.
# chmod +x mypienv/bin/activate
# mypienv/bin/activate
Missing '}'.
And you see that script not working but:
# ls mypienv/bin/
activate activate.fish easy_install-2.7 pip2.7 python2
activate_this.py activate.ps1 pip python python2.7
activate.csh easy_install pip2 python-config wheel
Finaly:
# python mypienv/bin/activate_this.py
And it worked!
P.S. I am new with python python verions 2.7
env/Scripts/activate worked for me.
For Windows, the following worked for me:
C:\.virtualenvs\env\Scripts>activate.bat