I am trying to create another virtual environment (I already installed one using the typical instructions found here: http://docs.python-guide.org/en/latest/dev/virtualenvs/) so I run:
$ virtualenv experimental
-> The program 'virtualenv' is currently not installed. You can install it by typing: sudo apt install virtualenv
I checked to see if perhaps the program needed to be updated:
$ pip install virtualenv --upgrade
-> Requirement already up-to-date: virtualenv in /home/uniside/.local/lib/python2.7/site-packages
Any ideas about what is going on here?
Use sudo. Currently it's being install in your local directory.
sudo pip install virtualenv
The answer by #khrm didn't worked for me.
I was able to do this with :
sudo apt install virtualenv
I had problems activating my virtualenv projects with Ubuntu's system version, so I just use pip's virtualenv. Works with python2 as well:
$ pip3 install virtualenv
Just call virutalenv via python3 -m:
$ python3 -m virtualenv --help
Usage: virtualenv.py [OPTIONS] DEST_DIR
Related
I can't install a package with the pip or pip3 command and I can't install it from the Python Interpreter in PyCharm too. I can't tap on the '+' at the Python Interpreter in PyCharm.
I get this error:
pip command not found
Here is what you can try.
Lets check python installation.
C:\Users\User>python --version
Python 3.10.5
C:\Users\User>
If you get the version as 3.x, then we are good, else goto your python installation directory and copy its path and then add it to your environment variable PATH.
Check PIP available or not.
C:\Users\User>pip --version
pip 22.3 from C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pip (python 3.10)
C:\Users\User>
if above didn't work then add pip path to PATH environment variable which would be something similar to above output.
Now we are ready to install any package
Just do pip install package-name
for testing, you can try:
pip install numpy
If it still throws error, try below one
python -m pip install numpy
if it still throws error, then you might need to clean your python installation.
3 commands
sudo apt update
sudo apt install python3-pip
pip3 install <package_name>
or maybe
sudo apt install <package_name> -y
It looks like you don't have pip installed on $PATH. The following command will run pip without any adjustments to $PATH:
python3 -m pip install <some_module>
Pay attention to the -m, this stands for modules and runs the pip program inside the python3 interpreter (I don't know exact definition here, if anyone wishes to correct me I will update the answer)
However, if this doesn't work then you may not have pip installed, and can be installed by running:
python3 -m ensurepip --upgrade
Then, reload your shell via the following (replace bash with your shell):
exec bash
Running pip --version should now work
I was creating a new virtual environment on Ubuntu 20.04:
$ virtualenv my_env
But it gave an error:
ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data'
Other info:
$ virtualenv --version
virtualenv 20.0.17 from /usr/lib/python3/dist-packages/virtualenv/__init__.py
#yushulx
I also ran into the same issue. I installed both via pip3 and via sudo apt install python3-virtualenv and it gave me an error but after I ran pip3 uninstall virtualenv I could create a virtualenv without issue
Try to create the virtual environment using directly venv module
python3 -m venv my_env
To fix this on Ubuntu 20.04, I had to uninstall virtualenv from the system: apt remove python3-virtualenv, and reinstall it using pip: pip install --user virtualenv --force-reinstall. I had errors about dependencies conflicts, I fixed them by calling pip install --user ${package} --force-reinstall for every package involved.
virtualenv is installed by default with python itself and when you install virtualenv via pip3 and try to create virtual environment using pipenv you will get this error:
ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data
check the version of installed virtualenv using apt list --installed
mine is:
python3-virtualenv/focal,focal,now 20.0.17-1 all [installed,automatic]
with the installed virtualenv by pip3
min is :
virtualenv 20.4.0
default installation of virtualenv is different with pip3 installed virtualenv
so when you try to create a virtual environment using pipenv for example installing django in a directory home/user/djano with pipenv install django~=3.1.5 you will get that error
the solution is remove installed virtualenv using pip3 uninstall virtualenv and use the default installation of virtualenv this time when you create virtual environment with pipenv it will create it successfully.
I want to have virtualenvwrapper. On Debian 10 testing I did:
apt remove python3-virtualenvwrapper # not purge, I want no changes in ~/.virtualenvs/
apt purge python3-virtualenv
/usr/bin/python3.8 -m pip install --force-reinstall virtualenvwrapper
/usr/bin/python3.8 -m pip install --force-reinstall virtualenv==20.0.23
.24 no longer works. I hope it will be solved sometimes...
EDIT 2021.01: I have changed my stack to: pyenv + pyenv-virtualenvwrapper + poetry. Ie. I use no apt or pip installation of virtualenv or virtualenvwrapper, and instead I install pyenv's plugin pyenv-virtualenvwrapper. This is easier way.
If someone encounters this problem inside existing env (when for example using pyenv) you can also use command below (found on GitHub when tried to fix poetry virtual env installation):
pip install --force-reinstall virtualenv
When I installed virtualenv via pip3, it failed to run virtualenv command. Then I changed the installation via:
sudo apt install python3-virtualenv
The virtualenv command can normally work.
I too had this issue. What I found is it is a permissions issue. For some unknown reason ownership of my home directory was off. I did a chown -R for the directory I was using for my project making myself the owner of my own directory and now everything works as normal.
I also had same issue, seems installed version has different user level so I followed their doc and below one work for me:
python3 -m virtualenv --help
To create new environment:
python3 -m virtualenv my_env
I also faced the same issue but after removing virtualenv which was installed with pip3, I could get rid of this error. Uninstall virtualenv with below command (don't forget to use sudo)
sudo pip3 uninstall virtualenv
After this, virtualenv command works totally fine.
It means that there are two virtualenv in your system.
One is "pip install" by sudo or root, the other may be installed by apt(if you are using ubuntu os)
Just uninstall one of them and the error should be fixed.
I fixed this error by removing all virtualenv and virtualenvwrapper related packages on system and reinstall the virtualenv and virtualenvwrapper with pip with below command(as i use ubuntu, so below only show apt)
remove all packages shown in below result
apt list --installed | grep virtualenvwrapper
apt list --installed | grep virtualenvwrapper
install virtualenv virtualenvwrapper with pip
pip install virtualenvwrapper virtualenvwrapper
set ~/.zshrc
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/amd
export VIRTUALENVWRAPPER_SCRIPT=/home/robot/.local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_PYTHON=$(which python3)
source /home/robot/.local/bin/virtualenvwrapper.sh
When we use pip3 or python3 to install virtualenv then I got that error too. I had to run each time to create virtualenv (my_env is virtual environment name)
python3 -m virtualenv my_env
But if I install it using
sudo apt install virtualenv
Then virtualenv command works fine.
virtualenv my_env
When I run the following command within my virtual env
sudo pip3 install -r requirements.txt
It says that the packages were successfully installed, but when I try to run or import the packages, it can not find them.
pip3 show returns nothing.
However, when I manually run
sudo pip3 install package-name
It installs the package just fine and it works.
Why is pip install -r requirements.txt not working? It always worked in the past. Now that I reinstalled Python it stopped working..
System:
Ubuntu 14.04
Python changed from 3.4 to 3.6.2
requirements.txt
Django==2.0.8
django-debug-toolbar
channels
Debugging in Terminal:
EDIT: This makes no sense.
pip3 install -r requirements.txt
Requirement already satisfied: pycparser in /usr/local/lib/python3.6/site-packages (from cffi!=1.11.3,>=1.8->cryptography>=2.7->autobahn>=0.18->daphne~=2.3->channels==2.3.0->-r requirements.txt (line 79)) (2.19)
$ pip3 --version
pip 19.2.3 from /home/dominic/Desktop/projects/printrender/env/lib/python3.6/site-packages/pip (python 3.6)
I install packages in my Virtual Environemnt using pip3 install -r requirements and it says that they are already installed, but when I run Pip Freeze, it returns nothing, as if nothing is installed.
Pip3 install -r requirements is placing my packages in my local packages python packages, and pip freeze is referencing my virtual env packages.
pip is not installing this packages in the correct place
I don't think you should use sudo when you're using a virtual environment. Try without.
I think you created a virtual environment for python 2 by mistake since pip3 is used from /usr/local/lib/python3.6 instead of in the env. You can create the virtual environment specifically for python3 by using the command
virtualenv -p python3 env
Could you try creating a new virtual environment with the command above and see if it works?
Using sudo was part of the issue and some of the packages in my requirements.txt were causing errors with the latest version of pip.
When you use sudo, you installed your packages globally. This must solve your problem.
sudo su
. venv/bin/activate
pip install -r requirements.txt
I've read a lot of blog post about this and I'm still confused as to what is "best" way to set it up. Most of the blog posts I've read are out-dated. I'm new to Linux and have messed up my system twice now and still can't setup the virtual environments properly. According to what I've read, Virtualenv and Virtualenvwrapper combination is the most widely used setup. So, After a fresh Ubuntu 16.04 LTS install, I do the following:
Install Python 3.6 as shown in the following link.
https://tecadmin.net/install-python-3-6-ubuntu-linuxmint/
The current state of the system now is,
$ python3.6 -V
Python 3.6.4
$ pip3.6 -V
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
pip3 (python3.5) and pip(python2.7) do not come pre-installed. To install them , I do:
$ sudo apt-get install python-pip
$ sudo apt-get install python3-pip
$ which pip
/usr/bin/pip
$ which pip3
/usr/bin/pip3
Now, the pip-version installed through apt-get method is old(version 8.1.1). We need to update it to (version 9.0.1). This is where it all goes wrong.
Question 1: How do I update the two different pip versions without breaking anything?
Assume, both pip versions are upgraded to version 9.0.1
Now, I have to install virtualenv and virtualenvwrapper.
Which pip version do I use to install it?
$ pip install --user virtualenv and $ pip install --user virtualenvwrapper
or
$ pip3 install --user virtualenv and $ pip3 install --user virtualenvwrapper
ps: I'm following this link-
http://chrisstrelioff.ws/sandbox/2016/09/21/python_setup_on_ubuntu_16_04.html
With python 3.6 virtual environments come built-in with the venv module:
python3.6 -m venv my-venv
To create a virtual environment for python 3.5:
virtualenv -p python3.5 env
To create a virtual environment for python 2.7:
virtualenv -p python2.7 env
Try using conda to set up virtual environments ?
With conda you can create a virtual environment and keep each of them separate from the root environment.
I wanted to deploy my Python app on Amazon Linux AMI 2015.09.1, which has Python2.7 (default) and pip (6.1.1). Then, I upgraded the pip using the command:
sudo pip install -U pip
However, it seemed broken, and showed the message when I tried to install packages:
pkg_resources.DistributionNotFound: pip==6.1.1
I found out that pip remove the previous files located in /usr/bin/, and installed the new one in /usr/local/bin. Thus, I tried to specify the location by using the command:
sudo pip install -U --install-option="--prefix='/usr/bin'" pip
Nevertheless, it still installed the new one in /usr/local/bin. In addition to that, pip could not work well with sudo although it successfully installed. The error message :
sudo: pip2.7: command not found
Is there a way to properly manage pip?
Try:
sudo which pip
This may reveal something like 'no pip in ($PATH)'.
If that is the case, you can then do:
which pip
Which will give you a path like /usr/local/bin/pip.
Copy + paste the path to pip to the sbin folder by running: sudo cp /usr/local/bin/pip /usr/sbin/
This will allow you to run sudo pip without any errors.
Struggled with this for a while. Here's what I've found:
ec2_user finds the pip executable, but has a module import error due to other having no read/execute permissions on the pip folders in the /usr/local/lib/python2.7/site-packages folder. This is actually okay, since in most cases, pip installs fail when not run as root anyway.
sudo cannot find pip.
Entering root with sudo su - allows pip to be run without issue.
The reason sudo pip stops working after the upgrade, is because the executable (or symbolic link) is removed from /usr/bin. However, what remains is a file called pip-27, which contains the following:
#!/usr/bin/python2.7
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==6.1.1','console_scripts','pip2.7'
__requires__ = 'pip==6.1.1'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('pip==6.1.1', 'console_scripts', 'pip2.7')()
)
So, that's where our error comes from, as the upgrade clearly doesn't clean this file up. Not entirely clear on where the name translation from pip to pip-2.7 occurs.
As mentioned in another answer, pip now exists in /usr/local/bin after the upgrade, which is no longer in the sudo secure path. You can add this path to the secure_path variable by running sudo visudo. Another alternative, if you'd prefer to not add that path to your secure_path is to make a symbolic link to the new pip executable in /usr/bin.
The problem is partly answered by your question. The Amazon AMI doesn't consider /usr/local/bin to be part of the root account's PATH. You can fix this by updating the root account's ~/.bashrc to include it.
Something like this...
export PATH=$PATH:/usr/local/bin
After struggling with this for hours and reading comments
which pip gave /usr/bin/pip , but the actual pip was located at /usr/local/bin/pip due to pip upgrade and clean up was not complete
So removing the pip in /usr/bin/
sudo rm /usr/bin/pip
and also adding the new pip to your export path
vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/bin
exit terminal, and login back
which pip should give /usr/local/bin/pip
pip install --upgrade pip
This works for me
sudo /usr/local/bin/pip install --upgrade pip
To add to angelokh
sudo `which pip` install --upgrade pip
I think the best strategy in this case is to manage pip is as part of a virtual environment using virtualenv rather than messing with the system-level version.
If you're OK with that, here's the basic idea:
Install the version of virtualenv packaged with the version of pip you are looking to upgrade to to the system-level pip (e.g. virtualenv==15.1.0 comes with pip==9.0.1):
$ sudo pip install -U virtualenv==15.1.0
You are using pip version 6.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting virtualenv==15.1.0
Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
100% |████████████████████████████████| 1.8MB 135kB/s
Installing collected packages: virtualenv
Found existing installation: virtualenv 12.0.7
Uninstalling virtualenv-12.0.7:
Successfully uninstalled virtualenv-12.0.7
Successfully installed virtualenv-15.1.0
I used the virtualenv release notes to find out which version of pip corresponds to which version of virtualenv.
Create the virtual environment:
$ virtualenv myenv
New python executable in /home/ec2-user/myenv/bin/python2.7
Also creating executable in /home/ec2-user/myenv/bin/python
Installing setuptools, pip, wheel...done.
Activate the virtual environment and confirm the version and location of the upgraded pip:
$ source myenv/bin/activate
(myenv) $ pip -V
pip 9.0.1 from /home/ec2-user/myenv/local/lib/python2.7/dist-packages (python 2.7)
(myenv) $ which pip
~/myenv/bin/pip
This should allow you to install packages to this virtualenv using the pip version of your choice, without the need for sudo.
I think you've didn't installed the pythonXX-pip package.
I've upgraded mine straight to Python3.4, these commands works for me.
sudo su
yum install python34
yum install python34-pip