I've created a virtualenv called venv and activated it. When using which both pip and pip3 point to the venv/bin folder. Yet when trying to install packages and listing them will there is a difference. When using pip all my global packages are listed and new packages are installed globally. With pip3 the behavior is as expected containing everything within the virtual environment.
Here is a small console log:
$ virtualenv venv
$ source venv/bin/activate
(venv)$ which pip
./venv/bin/pip
(venv)$ which pip3
./venv/bin/pip3
(venv)$ pip list
SHOWS GLOBAL PACKAGES
(venv)$ pip3 list
SHOWS LOCAL PACKAGES
How do I get the correct with pip using the virtual environment?
I am using Ubuntu 18.04.4 LTS with python 3.6.1 and pip 20.0.2.
Related
I have set up a virtual environment correctly have activated it and when I do "which python" it tells me the correct directory, but when I do pip install in the venv it installs the package in the default directory of the mac and not in my venv. I have tried using pycharm and installing packages with that, but it happens the same thing.
Edit:
Following I will do a walkthru of my steps, first I did python3 -m venv /path/to/new/virtual/environment, then I did source env/bin/activate, then I did which python and I got the intended directory, afterwards I did pip3 install numpy and I saw the installation process, then I did pip list and numpy was not there, I checked the directory manually and it still was not there. I retried all the same thing with pycharm with the same results.
Follow these steps in order -
In your current working directory :
python3 -m venv venv
source venv/bin/activate
(venv) pip3 install library_name
To check if libraries were properly installed or not :
(venv) pip3 freeze
and check if your installed libraries is displayed on the terminal screen or not.
To deactivate the virtual environment :
(venv) deactivate
This is due to permission issues
Run this command to change permission of your virtual environment folder
sudo chmod -R 777 venv
After activating your virtual environment
source venv/bin/activate
Then try to install Django by either Python3 or Python2
pip3 install django or pip install django
Then check the list of installed packages by either Python3 or Python2
pip3 list or pip list
NOTE: If you run sudo pip3 install django or pip install in virtual environment that is not writeable by default it will be installed outside of virtual environment
If you run pip3 install django or pip install in virtual environment that is not writtable by default it will be installed outside of virtual environment you will get OS Persmission Error
I have used pip3 and pip because you can install packages by either Python3 or Python2, thing to remember if you created virtual environment by Python3, use pip3 and if you created by using Python2 use pip.
I'm using Linux Mint 20.2 with two directories / and /home.
I used the following command to install virtualenv:
>>> sudo pip3 install virtualenv
It worked fine and it installed in the following path:
>>> virtualenv --version
virtualenv 20.0.17 from /usr/lib/python3/dist-packages/virtualenv/__init__.py
But when I tried to create an environment I got the following error:
>>> python3 -m venv article
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt install python3.8-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/home/username/article_tools/article/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
When I tried to uninstall it to install it using [b]sudo apt install python3.8-venv[/b], I got the following error:
>>> sudo pip3 uninstall virtualenv
Found existing installation: virtualenv 20.0.17
Not uninstalling virtualenv at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'virtualenv'. No files were found to uninstall.
How can I fix it? By fix, I mean installing virtualenv in a way that I don't get such errors.
The fundamental problem here seems to be that you are mixing up two different packages.
Python 3 comes with a built-in virtual environment module venv which is however not installed by default on Debian-based platforms. Like the error message says, apt-get install -y python3-venv will install this package, which you can then use with python3 -m venv.
virtualenv is a separate third-party package which you invoke with the command virtualenv. It's not a bad alternative, but if you are only just learning, I would suggest you simply ignore it for the time being.
When I run pip --version I get pip 20.2.4, but when I create a new venv such as
python -m venv venv
venv\Scripts\activate
pip --version
I suddenly get version pip 19.2.3 from the venv. I tried to search all my drives for older pip which might get used for creation of pip inside venv but I only found 20.2.4 versions.
Where does python -m venv take source for creating pip file in my venv?
NOTE: I am running on Windows as you can see by the way I active the venv.
I need to find the python packages within my virtual environment.
When I run pip freeze I can see all the packages in the virtual environment.
However, when I cd ./venv/ and run tree Pillow (or manually search) I cannot find any installed package.
Any idea where they are stored?
Ask pip to tell you where it installed the project with the following command:
$ path/to/venv/bin/python -m pip show --files Pillow
from virtualenv do pip -V
It will be in : <virtual env root dir> + lib
example from my terminal
(vams_test) C:\VAMS\jiras\vams>pip -V
pip 19.2.3 from c:\vams\code\copy_v0.1\vams_test\lib\site-packages\pip (python 3.7)
I'm not sure if I set up this venv wrong or what
This is how I created it :
python -m venv venv
Entering it :
venv/Scripts/activate
And then pip freeze :
(venv) pip freeze
I've tried pip3, pip3.6, pip, they all give me the list from global pip, I only want the list of installed packages inside the venv, how to do it?