virtualenv is not picking python3 automatically from /usr/bin - python

I have installed new ubuntu 18.4 and while solving some other error while installing requirements through pip. I tried installing python-setuptools and python-dev instead of installing python3-setuptools and python3-dev which in turn installed python2.7 on my machine. Well the solution didn't work and I removed the packages as I don't want 2.7 on my machine and now when I run the following command:
sudo virtualenv venv
I get this message: The path python2 (from --python=python2) does not exist.
before installing python-dev and python-setup tools the above command worked fine.
I have tried replacing python symbolic link to python3.6 in /usr/bin.
by executing: ln -s /usr/bin/python3.6 /usr/bin/python although I am able to get python3.6 console every time run python like on fresh install of ubuntu but I can't creat virtual environment the same way.

Try yo run it with this specific python
/usr/bin/python3.6 -m pip install virtualenv
sudo /usr/bin/python3.6 -m virtualenv venv
and delete the python2.7 is probably a bad idea cause there is probably thing that using it on your machine, and also, consider reading about system envirmate varibles, as PATH for example that would solve you problem

Related

zsh: /usr/local/bin/pipenv: bad interpreter: /usr/local/opt/python/bin/python3.7: no such file or directory

I recently switched from bash to zsh (MacOS). I haven't used pipenv since the switch. Now when I run any pipenv command I get the following error:
$ pipenv install
zsh: /usr/local/bin/pipenv: bad interpreter: /usr/local/opt/python/bin/python3.7: no such file or directory
I use pyenv for Python dependency management:
$ which python
/Users/ryan.payne/.pyenv/shims/python
My default python version is 3.7.3:
$ pyenv versions
system
2.7.16
3.6.8
* 3.7.3 (set by /Users/ryan.payne/.pyenv/version)
It seems like pipenv is not using my pyenv version of Python. How do I get pipenv working again?
You don't need to uninstall anything. Simply change the interpreter at /usr/local/bin and have your current python path in pyenv handy:
type python3
copy the path
vi /usr/local/bin/pipenv
It will look something like this:
Once it's changed, you will probably have to download pipenv again. Don't worry, your env is fine.
pip install pipenv
Go play in your env
I had this same error with awscli. The solution was to install python#3.7 via homebrew and then cp that installation into the directory awscli expected.
brew install python#3.7
cp -r /usr/local/opt/python#3.7/bin/python3.7 /usr/local/opt/python/bin/python3.7
Run in terminal:
brew install python3 && cp /usr/local/bin/python3 /usr/local/bin/python
After brew installation, sometimes it may not work.
Depending on whether you tried to install other python versions, the links might not be working any more, and therefore running the command
brew install python3 && cp /usr/local/bin/python3 /usr/local/bin/python
Might give an error as below
Error: Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists.
Try to remove the file 2to3
rm '/usr/local/bin/2to3'
and run the above code again
Alternatively, you can force the linkage
brew link --overwrite python#<version>
but you can first see the files that will be deleted by this forced linking using the command
brew link --overwrite --dry-run python#<version>
I hope this gives more light
If you installed pipenv with pipenv with pipx, then you can reinstall pipenv via pipx reinstall pipenv which should detect any top level changes in your python environment.

bash: virtualenv: command not found "ON Linux"

I am using a form of Lubuntu called GalliumOS (optimized for Chromebooks). I installed pip using $ sudo apt-get install python-pip. I then used pip install --user virtualenv and pip install virtualenv, and then when I tried to subsequently use virtualenv venv I experienced the message bash: virtualenv: command not found.
Between the pip installs above, I used pip uninstall virtualenv to get back to square one. The error remained after a reinstall.
I read several other posts, but all of them seemed to deal with similar problems on MacOS. One that came close was installing python pip and virtualenv simultaneously. Since I had already installed pip, I didn't think that these quite applied to my issue. Why is pip install virtualenv not working this way on LUbuntu / GalliumOS?
Are you sure pip install is "failing"? To me, it sounds like the directory to which pip is installing modules on your machine is not in your PATH environment variable, so when virtualenv is installed, your computer has no idea where to find it when you just type in virtualenv.
Find where pip is installing things on your computer, and then check if the directory where the pyenv executable is placed is in your PATH variable (e.g. by doing echo $PATH to print your PATH variable). If it's not, you need to update your PATH variable by adding the following to your .bashrc or .bash_profile or etc.:
export PATH="PATH_TO_WHERE_PIP_PUTS_EXECUTABLES:$PATH"
What finally worked for me was this. I used
$ sudo apt-get install python-virtualenv.
I was then able to create a virtual environment using $ virtualenv venv.
I was seeking to avoid using $ sudo pip install virtualenv, because of admonitions in other posts to not do this, and agreed, because of experiences I'd had with subsequent difficulties when doing this.
pip install virtualenv
This command worked for me for. This problem that raised to me on Kali Linux.

Pip not working inside Virtual Env but works outside perfectly

Hello Guys I am tying to follow the installation here https://github.com/systers/portal and trying to deploy the server inside a virtual environment on my machine.
After lots of errors I decided to install a fresh copy of Ubuntu 16.04 and start
After the installation here are the things that I have installed using the given commands
I checked my current python and python3 versions using python --version and python3--version respectively and they are Python 2.7.12 and Python 3.5.2 respectively.
Easy Install. $ sudo apt-get install python-setuptools python-dev build-essential
pip. $ sudo easy_install pip
virtualenv. $ sudo pip install --upgrade virtualenv.
python3-dev tools.$sudo apt-get install python3-dev
Now after that I created a virtual env and activated it using the following commands
$ virtualenv venv1 --python=/usr/bin/python3
$ source venv/bin/activate
But now when I run the third command
$ pip install -r requirements/dev.txt
or even do
$pip --version
I get the error
bash: /media/rohan/New Volume/portal/venv1/bin/pip: "/media/rohan/New: bad interpreter: No such file or directory
Also in /venv1/bin the files pip,pip3 ,pip3.5 are present
I tried sudo easy_install pip thinking that it will install pip in the virtual environment but it installs to /usr/local/bin
Also I tried by creating a virtual env using the code
$virtualenv venv --python=/usr/bin/python
But that also doesnt work and this time also same error comes and in /venv/bin pip pip2 pip2.7 are present
PLEASE HELP
The problem appears to be that the path to your virtualenv has a space in it that isn't being escaped somewhere it should be.
Note the error you receive:
/media/rohan/New: bad interpreter: No such file or directory
So with that space in the path, it is trying to run a program that doesn't exist (/media/rohan/New) on a file that doesn't exist (Volume/portal/venv1/bin/pip).
Renaming New Volume to something without spaces like new_volume and then recreating a virtualenv should resolve this.
I had renamed the folder of virtual environment so that I was getting this error.
Then I renamed the venv folder name to the path mentioned in the error (That is the one which I had named while creating venv.) then tried to use pip and it worked.
Might be you have already solved your issue, but this is for the future visitors.

osx install packages inside virtualenv

I tried to start virtualenv WITHOUT sudo but unfortunately it cannot find (Permission denied) /lib/python2.7/site-packages/easy_install.py. So I did:
sudo virtualenv name_env
The problem is that now pip is the global version (not inside pip):
which pip:
/usr/local/bin/pip
So I cannot install any package inside the environment.
If I start virtualenv without sudo:
virtualenv name_env
OSError: Command /Users/andrea/package_lambda/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 2
Any suggestion?
Don't use sudo just because you can!
I suggest you install another Python environment using brew, and then install pip, and subsequently virtualenv. This way, you'll substantially correct the underlying problem.
I would follow this method:
brew install pyenv
pyenv install 2.7.11
Or check the available versions through:
pyenv versions
This way, you can install different versions and switch between them as you wish, for instance:
pyenv global 2.7.11
And then you can install pip like so:
python -m easy_intall pip
and then install virtualenv like so:
python -m pip install virtualenv
As pouria mentioned, I believe it's a good idea to make sure you installed virtualenv using pip in the first place. I also agree that on OSX, using sudo should be rare.
As mentioned on a previous answer, you should also check that the files in the bin of your virtual env are correct.
I found the solution myself. I was using iterm instead of terminal (standard mac OS X). Using terminal I did:
sudo pip uninstall virtualenv
sudo pip install virtualenv
sudo cp /usr/local/bin/virtualenv /bin/virtualenv
Then I can create start a virtualenv:
virtualenv name_env
source name_env/bin/activate
To install python package on it I use:
sudo pip install --target=name_env/lib/python2.7/site-packages/ package name
I have the following file ~/.pydistutils.cfg with the contents
[install]
prefix=
temporarily removing this file fixed the issue for me (i had this file in place to address a different issue)

Error With Installing Virtualenv With Pip and Homebrew

I am trying to get a nice clean Python environment setup on OSX 10.9. I've installed Python with Homebrew and set my PATH variables so...
> which python
/usr/local/bin/python
and
> which pip
/usr/local/bin/pip
so when I look at my /usr/local/bin :
pip -> ../Cellar/python/2.7.6/bin/pip
python -> ../Cellar/python/2.7.6/bin/python
then when I run:
> pip install virtualenv
I get permission errors on /usr/local/bin/virtualenv:
...
running install_scripts
Installing virtualenv script to /usr/local/bin
error: /usr/local/bin/virtualenv: Permission denied
I thought that by using Homebrew I could use pip and avoid using sudo to install virtualenv. Am I doing something wrong here?
Ok! I managed to fix this myself.
I deleted all the virtualenv related things from /usr/local/bin (they had been installed under root for some reason and this was causing my permission issues.).
Then I did a pip uninstall virtualenv to get rid of other instances of virtualenv, as there was still one in /usr/local/lib/python2.7/site-packages/
Then a simple pip install virtualenv and things work fine now!
Most likely HomeBrew does some magic so that running brew install allows writing to /usr/local/bin, but this privilege is not available to normal commands. This is a guess, I didn't investigate this further.
Install virtualenv with brew:
brew install pyenv-virtualenv
This command:
pip install virtualenv
runs pip from your first directory from $PATH environment variable, which is usually system wide, thus when you run in this way - you are trying to install it globall.
You should install you your environment in your $HOME directory:
virtualenv $HOME/myvirpython
and later:
$HOME/myvirpython/bin pip install something
Additionally you should read this:
https://docs.brew.sh/Homebrew-and-Python

Categories

Resources