Working with multiple project or in a an already configured system, using virtual environment will protect you against messing up the initial configuration. Don’t use pip with sudo unless you setup for the first time your system wide virtual environment package/configuration. Otherwise, it may cause a discrepancy among existing versions.
To get started with pip let’s install it:
- Debian:
— For python 2 —
apt install python-pip
— For python 3 —
apt install python3-pip - Centos:
yum install epel-release
yum install python-pip
Using some basic pip commands you can list packages, show a package details, install or uninstall packages.
- pip list, shows installed packages.
- pip show package_name, shows detail of a given package and its location.
- pip uninstall package_name, uninstall a package.
To use pip’s specific version i.e with python3.x, use pip3 instead of pip. Because pip is checking your default path which is defined in your system confiugration to locate your python executable command.
python3 -m pip install requests, is able to locate your python3 directory tree and install packages within this directory otherwise, pip alone, will take into consideration your default python path, generally the path used for python2.7, as this version comes with default linux installations mostly.
Check the example below (Remember using sudo is not a good idea but sometimes I do :)) )
We have requests package version 2.6.0 installed for python 2.7 (It’s default python version coming with system installation).
And for python version 3 we installed requests package version “2.24.0”.
Otherwise, you encounter version or dependency conflicts and get an error message. So, that’s why it’s a best pratice to work with virtual environment.
Virtual Environment Setup & Usage
1 2 3 4 5 6 7 8 9 |
## To install python -m pip install virtualenv C:\Users\mufit\Documents\linux\python\courses_notes\Managing Python Packages and Virtual Environments\demos&slides>virtualenv --version virtualenv 20.0.23 from c:\users\mufit\anaconda3\lib\site-packages\virtualenv\__init__.py ## virtualenv --version command must show the right version. Otherwise delete it and reinstall globally: sudo python -m pip install virtualenv |
As you see I’m using python2.7 here. I installed a virtual environment for python 3 too. “python3 -m pip install virtualenv”. Now check the difference:
I’ve two virtual environment for both python versions.
1 2 3 4 5 |
[mufit@localhost ~]$ python3 -m virtualenv --version virtualenv 20.0.23 from /usr/local/lib/python3.6/site-packages/virtualenv/__init__.py [mufit@localhost ~]$ python -m virtualenv --version virtualenv 20.0.23 from /home/mufit/.local/lib/python2.7/site-packages/virtualenv/__init__.pyc [mufit@localhost ~]$ |
Now it’s time create our first customized virtual environment with a dedicated directory.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[mufit@localhost ~]$ pwd /home/mufit [mufit@localhost ~]$ mkdir virtenvs_python [mufit@localhost ~]$ cd virtenvs_python/ [mufit@localhost virtenvs_python]$ ll total 0 [mufit@localhost virtenvs_python]$ virtualenv test created virtual environment CPython2.7.5.final.0-64 in 587ms creator CPython2Posix(dest=/home/mufit/virtenvs_python/test, clear=False, global=False) seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/home/mufit/.local/share/virtualenv/seed-app-data/v1.0.1) activators PythonActivator,CShellActivator,FishActivator,PowerShellActivator,BashActivator [mufit@localhost virtenvs_python]$ ll total 0 drwxrwxr-x. 5 mufit mufit 77 Jun 18 18:07 test [mufit@localhost virtenvs_python]$ ll test/ total 8 drwxrwxr-x. 2 mufit mufit 4096 Jun 18 18:07 bin drwxrwxr-x. 3 mufit mufit 23 Jun 18 18:07 lib drwxrwxr-x. 3 mufit mufit 23 Jun 18 18:07 lib64 -rw-rw-r--. 1 mufit mufit 201 Jun 18 18:07 pyvenv.cfg [mufit@localhost virtenvs_python]$ |
I’ll setup another virtual environment, this time for python 3.
1 2 3 4 5 6 7 8 9 10 11 |
[mufit@localhost ~]$ virtualenv -p python3 examples_py3 created virtual environment CPython3.6.8.final.0-64 in 665ms creator CPython3Posix(dest=/home/mufit/examples_py3, clear=False, global=False) seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/home/mufit/.local/share/virtualenv/seed-app-data/v1.0.1) activators PythonActivator,FishActivator,XonshActivator,CShellActivator,PowerShellActivator,BashActivator [mufit@localhost ~]$ ll total 0 drwxr-xr-x. 2 mufit mufit 6 Apr 21 15:57 Desktop drwxr-xr-x. 3 mufit mufit 21 May 21 20:25 Documents drwxr-xr-x. 2 mufit mufit 29 Apr 21 16:09 Downloads drwxrwxr-x. 5 mufit mufit 77 Jun 18 18:13 examples_py3 |
virtualenv -p python3 examples_py3
-p sets python interpreter.
examples_py3 is the name of directory. If it doesn’t exist, will be created.
Before starting to work with virtual environment you must firstly activate it. Under examples_py3 directory we have bin/activate.sh. For windows under examples_py3 we have Scripts/activate.bat file. Run the script (don’t execute source it), prompt will be marked with virtual environment name. Type “deactivate” to return back in your terminal.
1 2 3 4 |
[mufit@localhost ~]$ . examples_py3/bin/activate (examples_py3) [mufit@localhost ~]$ python -V Python 3.6.8 (examples_py3) [mufit@localhost ~]$ |
Our python interpreter has version 3.6.8
I’ve a script requiring “request” package. I’ll install this package on my virtual environment and run the script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
(examples_py3) [mufit@localhost ~]$ python /tmp/rates.py Traceback (most recent call last): File "/tmp/rates.py", line 1, in import requests ModuleNotFoundError: No module named 'requests' ## HERE I CAN USE PIP WITHOUT python3 -m pip BECAUSE I'M ALREADY IN MY ## VIRTUAL ENVIRONMENT FOR PYTHON 3 (examples_py3) [mufit@localhost ~]$ pip install requests Collecting requests Using cached requests-2.24.0-py2.py3-none-any.whl (61 kB) Collecting idna<3,>=2.5 Using cached idna-2.9-py2.py3-none-any.whl (58 kB) Collecting certifi>=2017.4.17 Using cached certifi-2020.4.5.2-py2.py3-none-any.whl (157 kB) Collecting chardet<4,>=3.0.2 Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB) Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 Using cached urllib3-1.25.9-py2.py3-none-any.whl (126 kB) Installing collected packages: idna, certifi, chardet, urllib3, requests Successfully installed certifi-2020.4.5.2 chardet-3.0.4 idna-2.9 requests-2.24.0 urllib3-1.25.9 (examples_py3) [mufit@localhost ~]$ python /tmp/rates.py {"rates":{"USD":1.1222},"base":"EUR","date":"2020-06-18"} (examples_py3) [mufit@localhost ~]$ |
Of course installing one or two packages is not a big deal but what if you have more than 3 packages to install ? You can handle multiple package installation by one command with the help of requirements.txt file.
python -m pip freeze command prints all packages already installed. you can redirect the output to requirements.txt file and share this with your collegues that you work together on the same project. Later you can install all packages with python -m pip install -r requirements.txt.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
(examples_py3) [mufit@localhost ~]$ pip list Package Version ---------- ---------- certifi 2020.4.5.2 chardet 3.0.4 idna 2.9 pip 20.1.1 requests 2.24.0 setuptools 47.1.1 urllib3 1.25.9 wheel 0.34.2 (examples_py3) [mufit@localhost ~]$ pip freeze certifi==2020.4.5.2 chardet==3.0.4 idna==2.9 requests==2.24.0 urllib3==1.25.9 (examples_py3) [mufit@localhost ~]$ pip freeze > requirements.txt (examples_py3) [mufit@localhost ~]$ ls Desktop Documents Downloads examples_py3 Music Pictures Public requirements.txt Templates Videos virtenvs_python (examples_py3) [mufit@localhost ~]$ cat requirements.txt certifi==2020.4.5.2 chardet==3.0.4 idna==2.9 requests==2.24.0 urllib3==1.25.9 (examples_py3) [mufit@localhost ~]$ |
Inside this requirements file I’ll add a new package (just append in last line), flask framework then we will see how to install them from requirement.txt file.
Flask==1.1.2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
(examples_py3) [mufit@localhost ~]$ cat requirements.txt certifi==2020.4.5.2 chardet==3.0.4 idna==2.9 requests==2.24.0 urllib3==1.25.9 Flask==1.1.2 ## New package inserted here. (examples_py3) [mufit@localhost ~]$ (examples_py3) [mufit@localhost ~]$ pip install -r requirements.txt Requirement already satisfied: certifi==2020.4.5.2 in ./examples_py3/lib/python3.6/site-packages (from -r requirements.txt (line 1)) (2020.4.5.2) Requirement already satisfied: chardet==3.0.4 in ./examples_py3/lib/python3.6/site-packages (from -r requirements.txt (line 2)) (3.0.4) Requirement already satisfied: idna==2.9 in ./examples_py3/lib/python3.6/site-packages (from -r requirements.txt (line 3)) (2.9) Requirement already satisfied: requests==2.24.0 in ./examples_py3/lib/python3.6/site-packages (from -r requirements.txt (line 4)) (2.24.0) Requirement already satisfied: urllib3==1.25.9 in ./examples_py3/lib/python3.6/site-packages (from -r requirements.txt (line 5)) (1.25.9) Collecting Flask==1.1.2 Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB) |████████████████████████████████| 94 kB 1.4 MB/s Collecting Werkzeug>=0.15 Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB) |████████████████████████████████| 298 kB 1.8 MB/s Collecting Jinja2>=2.10.1 Downloading Jinja2-2.11.2-py2.py3-none-any.whl (125 kB) |████████████████████████████████| 125 kB 1.9 MB/s Collecting itsdangerous>=0.24 Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB) Collecting click>=5.1 Downloading click-7.1.2-py2.py3-none-any.whl (82 kB) |████████████████████████████████| 82 kB 1.0 MB/s Collecting MarkupSafe>=0.23 Downloading MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl (27 kB) Installing collected packages: Werkzeug, MarkupSafe, Jinja2, itsdangerous, click, Flask Successfully installed Flask-1.1.2 Jinja2-2.11.2 MarkupSafe-1.1.1 Werkzeug-1.0.1 click-7.1.2 itsdangerous-1.1.0 (examples_py3) [mufit@localhost ~]$ (examples_py3) [mufit@localhost ~]$ pip list Package Version ------------ ---------- certifi 2020.4.5.2 chardet 3.0.4 click 7.1.2 Flask 1.1.2 ## FLASK SUCCESSFULY INSTALLED FROM REQUIREMENTS.TXT idna 2.9 itsdangerous 1.1.0 Jinja2 2.11.2 MarkupSafe 1.1.1 pip 20.1.1 requests 2.24.0 setuptools 47.1.1 urllib3 1.25.9 Werkzeug 1.0.1 wheel 0.34.2 (examples_py3) [mufit@localhost ~]$ |
Virtualenvwrapper
It searches and detects virtual environments installed on the computer. Install virtuealenvwrapper with sudo python -m pip install virtualenvwrapper then append the virtualenvwrapper.sh in your user’s .profile or .bash_profile file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
[mufit@localhost ~]$ sudo python -m pip install virtualenvwrapper [sudo] password for mufit: DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support Collecting virtualenvwrapper Downloading virtualenvwrapper-4.8.4.tar.gz (334 kB) |████████████████████████████████| 334 kB 1.8 MB/s Collecting virtualenv Using cached virtualenv-20.0.23-py2.py3-none-any.whl (4.7 MB) Collecting virtualenv-clone Downloading virtualenv_clone-0.5.4-py2.py3-none-any.whl (6.6 kB) Collecting stevedore Downloading stevedore-1.32.0-py2.py3-none-any.whl (43 kB) |████████████████████████████████| 43 kB 501 kB/s Collecting distlib<1,>=0.3.0 Using cached distlib-0.3.0.zip (571 kB) Collecting filelock<4,>=3.0.0 Downloading filelock-3.0.12.tar.gz (8.5 kB) Requirement already satisfied: six<2,>=1.9.0 in /usr/lib/python2.7/site-packages (from virtualenv->virtualenvwrapper) (1.9.0) Collecting pathlib2<3,>=2.3.3; python_version < "3.4" and sys_platform != "win32" Downloading pathlib2-2.3.5-py2.py3-none-any.whl (18 kB) Collecting contextlib2<1,>=0.6.0; python_version < "3.3" Downloading contextlib2-0.6.0.post1-py2.py3-none-any.whl (9.8 kB) Collecting appdirs<2,>=1.4.3 Using cached appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB) Collecting importlib-metadata<2,>=0.12; python_version < "3.8" Using cached importlib_metadata-1.6.1-py2.py3-none-any.whl (31 kB) Collecting importlib-resources>=1.0; python_version < "3.7" Using cached importlib_resources-2.0.1-py2.py3-none-any.whl (22 kB) Collecting pbr!=2.1.0,>=2.0.0 Downloading pbr-5.4.5-py2.py3-none-any.whl (110 kB) |████████████████████████████████| 110 kB 665 kB/s Collecting scandir; python_version < "3.5" Downloading scandir-1.10.0.tar.gz (33 kB) Collecting zipp>=0.5 Downloading zipp-1.2.0-py2.py3-none-any.whl (4.8 kB) Collecting configparser>=3.5; python_version < "3" Downloading configparser-4.0.2-py2.py3-none-any.whl (22 kB) Collecting singledispatch; python_version < "3.4" Downloading singledispatch-3.4.0.3-py2.py3-none-any.whl (12 kB) Collecting typing; python_version < "3.5" Downloading typing-3.7.4.1-py2-none-any.whl (26 kB) Using legacy setup.py install for virtualenvwrapper, since package 'wheel' is not installed. Using legacy setup.py install for distlib, since package 'wheel' is not installed. Using legacy setup.py install for filelock, since package 'wheel' is not installed. Using legacy setup.py install for scandir, since package 'wheel' is not installed. ERROR: stevedore 1.32.0 has requirement six>=1.10.0, but you'll have six 1.9.0 which is incompatible. Installing collected packages: distlib, filelock, scandir, pathlib2, contextlib2, appdirs, zipp, configparser, importlib-metadata, singledispatch, typing, importlib-resources, virtualenv, virtualenv-clone, pbr, stevedore, virtualenvwrapper Running setup.py install for distlib ... done Running setup.py install for filelock ... done Running setup.py install for scandir ... done Running setup.py install for virtualenvwrapper ... done Successfully installed appdirs-1.4.4 configparser-4.0.2 contextlib2-0.6.0.post1 distlib-0.3.0 filelock-3.0.12 importlib-metadata-1.6.1 importlib-resources-2.0.1 pathlib2-2.3.5 pbr-5.4.5 scandir-1.10.0 singledispatch-3.4.0.3 stevedore-1.32.0 typing-3.7.4.1 virtualenv-20.0.23 virtualenv-clone-0.5.4 virtualenvwrapper-4.8.4 zipp-1.2.0 [mufit@localhost ~]$ [mufit@localhost ~]$ locate virtualenvwrapper.sh /usr/bin/virtualenvwrapper.sh [mufit@localhost ~]$ vim .bash_profile [mufit@localhost ~]$ cat .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/.local/bin:$HOME/bin export PATH source /usr/bin/virtualenvwrapper.sh ## HERE APPEND THESE 2 LINES export WORKON_HOME="/home/mufit/virt_envs_python" [mufit@localhost ~]$ |
After restart your shell session, “virtualenvwrapper.sh” script will be sourced. It gives you to use “workon” command, your existing virtual environments under “/home/your_user/virt_envs_python” will be printed.
- workon virtual_environment_name, activates the environment.
If you want to setup a dedicated workspace for your projects you can append folloqing line to your ~/.profile or ~/.bash_profile file:
PROJECT_HOME=”/home/your_user/virt_envs_python”
Then create folder “/home/your_user/virt_envs_python”
- mkproject new_project, creates new_project directory under your workspace and setup a dedicated virtual environment for this project. By this way, even if you are inside another file system, when activating your virtual environment you will be redirected to your workspace. But it doesn’t work for manually configured virtual environments. To do so, you should type “setvirtualenvproject” command when you activated your virtual environment and you are inside the directory which belongs to your environment.
Ex:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
## I'VE 2 VIRTUAL ENVIRONMENT [mufit@localhost ~]$ workon ex_python3 ex_python [mufit@localhost ~]$ [mufit@localhost ~]$ ll virt_envs_python/ total 0 drwxrwxr-x. 5 mufit mufit 77 Jun 18 20:46 ex_python drwxrwxr-x. 5 mufit mufit 77 Jun 18 20:49 ex_python3 ### CREATE NEW ENVIRONMENTS [mufit@localhost ~]$ setvirtualenvproject ~/virt_envs_python/ Setting project for virt_envs_python to /home/mufit [mufit@localhost ~]$ [mufit@localhost ~]$ mkproject others created virtual environment CPython3.6.8.final.0-64 in 253ms creator CPython3Posix(dest=/home/mufit/virt_envs_python/others, clear=False, global=False) seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/home/mufit/.local/share/virtualenv/seed-app-data/v1.0.1) activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator virtualenvwrapper.user_scripts creating /home/mufit/virt_envs_python/others/bin/predeactivate virtualenvwrapper.user_scripts creating /home/mufit/virt_envs_python/others/bin/postdeactivate virtualenvwrapper.user_scripts creating /home/mufit/virt_envs_python/others/bin/preactivate virtualenvwrapper.user_scripts creating /home/mufit/virt_envs_python/others/bin/postactivate virtualenvwrapper.user_scripts creating /home/mufit/virt_envs_python/others/bin/get_env_details Creating /home/mufit/virt_envs_python/others Setting project for others to /home/mufit/virt_envs_python/others ## I'M AUTOMATICALLY IN MY NEW PROJECT & VIRTUAL ENVIRONMENT (others) [mufit@localhost others]$ ## IN TOTAL I'VE 4 VIRTUAL ENVS (others) [mufit@localhost others]$ workon ex_python3 ex_python new_project others (others) [mufit@localhost others]$ cd .. (others) [mufit@localhost virt_envs_python]$ ll total 0 drwxrwxr-x. 5 mufit mufit 77 Jun 18 20:46 ex_python drwxrwxr-x. 5 mufit mufit 77 Jun 18 20:49 ex_python3 drwxrwxr-x. 5 mufit mufit 93 Jun 18 20:52 new_project drwxrwxr-x. 5 mufit mufit 93 Jun 19 12:19 others (others) [mufit@localhost virt_envs_python]$ ## I'VE CHANGED THE DIRECTORY EACH TIME I ACTIVATE ANOTHER VIRTUAL ENV, I'LL BE SWITCHING TO ITS WORKING SPACE. CHECK PROMPT: [mufit@localhost tmp]$ workon ex_python (ex_python) [mufit@localhost new_project]$ cd ../ex_python (ex_python) [mufit@localhost ex_python]$ setvirtualenvproject Setting project for ex_python to /home/mufit/virt_envs_python/ex_python (ex_python) [mufit@localhost ex_python]$ workon ex_python3 (ex_python3) [mufit@localhost new_project]$ cd ../ex_python3 (ex_python3) [mufit@localhost ex_python3]$ setvirtualenvproject Setting project for ex_python3 to /home/mufit/virt_envs_python/ex_python3 (ex_python3) [mufit@localhost ex_python3]$ ## NOW I SWITCH BETWEEN DIRECTORIES EACH TIME I ACTIVATE NEW ENVIRONMENT. (ex_python3) [mufit@localhost ex_python3]$ (ex_python3) [mufit@localhost ex_python3]$ workon others (others) [mufit@localhost others]$ cd /tmp (others) [mufit@localhost tmp]$ workon ex_python (ex_python) [mufit@localhost ex_python]$ |
Pipenv
The other option to work with virtual environments is installing “pipenv”. This creates under your working directory a virtual environment, install packages and dependencies. This can be useful when you work with others on a project together. Like “requirements.txt”, pipenv keeps informations about your interpreter, packages,versions and many other specifications.
- sudo pip install pipenv, to install.
- Go to your working directory. Ex: cd /home/projects/web_project
- pipenv install pacakge_1 package_2 package_n, you can install one or more packages at one time.
- In your working directory you will find two files: Pipfile (all configuration of your environment) and Pipfile.lock (contains hashes and package details).
- When exiting from your virtual environment, type “exit” instead of “deactivate”.
- pipenv shell, to work with virtual environment.
- pipenv install –three, installs everything for python 3. Check also your pip file to configure your interpreter if it’s required.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
[mufit@localhost virt_envs_python]$ cd pipenv_projects/ [mufit@localhost pipenv_projects]$ pipenv install requests python-box Creating a virtualenv for this project... Pipfile: /home/mufit/virt_envs_python/pipenv_projects/Pipfile Using /usr/bin/python3.6 (3.6.8) to create virtualenv... ⠇ Creating virtual environment...created virtual environment CPython3.6.8.final.0-64 in 471ms creator CPython3Posix(dest=/home/mufit/virt_envs_python/pipenv_projects-B-GlMTRV, clear=False, global=False) seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/home/mufit/.local/share/virtualenv/seed-app-data/v1.0.1) activators PythonActivator,FishActivator,XonshActivator,CShellActivator,PowerShellActivator,BashActivator ✔ Successfully created virtual environment! Virtualenv location: /home/mufit/virt_envs_python/pipenv_projects-B-GlMTRV Creating a Pipfile for this project... Installing requests... Adding requests to Pipfile's [packages]... ✔ Installation Succeeded Installing python-box... Adding python-box to Pipfile's [packages]... ✔ Installation Succeeded Pipfile.lock not found, creating... Locking [dev-packages] dependencies... Locking [packages] dependencies... Building requirements... Resolving dependencies... ✔ Success! Updated Pipfile.lock (402968)! Installing dependencies from Pipfile.lock (402968)... 🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00 To activate this project's virtualenv, run pipenv shell. Alternatively, run a command inside the virtualenv with pipenv run. [mufit@localhost pipenv_projects]$ ll total 12 -rw-rw-r--. 1 mufit mufit 170 Jun 19 12:38 Pipfile -rw-r--r--. 1 mufit mufit 4967 Jun 19 12:38 Pipfile.lock [mufit@localhost pipenv_projects]$ cat Pipfile [[source]] name = "pypi" url = "https://pypi.org/simple" verify_ssl = true [dev-packages] [packages] requests = "*" python-box = "*" [requires] python_version = "3.6" mufit@localhost pipenv_projects]$ pipenv shell Launching subshell in virtual environment... . /home/mufit/virt_envs_python/pipenv_projects-B-GlMTRV/bin/activate [mufit@localhost pipenv_projects]$ . /home/mufit/virt_envs_python/pipenv_projects-B-GlMTRV/bin/activate (pipenv_projects) [mufit@localhost pipenv_projects]$ pip list Package Version ---------------- ---------- certifi 2020.4.5.2 chardet 3.0.4 idna 2.9 pip 20.1.1 python-box 4.2.3 requests 2.24.0 ruamel.yaml 0.16.10 ruamel.yaml.clib 0.2.0 setuptools 47.1.1 toml 0.10.1 urllib3 1.25.9 wheel 0.34.2 (pipenv_projects) [mufit@localhost pipenv_projects]$ exit exit |
It has more user friendly interface. If you work with github you should put Pipfile and Pipfile.lock in your repository. Because when a developper or another person clones your project, this person can install all requirements from Pipfile by type simple command “pipenv install”. All packages and dependencies related to this project will be installed.
When you install a new package, your Pipfile and Pipfile.lock are automatically updated.
- pipenv update –outdated, to update all packages. In my case, accorfing to my system and Pipfile everything is up to date.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[mufit@localhost pipenv_projects]$ pipenv update --outdated Building requirements... Resolving dependencies... ✔ Success! Skipped Update of Package ruamel.yaml: 0.16.10 installed,, 0.16.10 available. Skipped Update of Package urllib3: 1.25.9 installed,, 1.25.9 available. Skipped Update of Package toml: 0.10.1 installed,, 0.10.1 available. Skipped Update of Package chardet: 3.0.4 installed,, 3.0.4 available. Skipped Update of Package requests: 2.24.0 installed, 2.24.0 required (Unpinned in Pipfile), 2.24.0 available. Skipped Update of Package certifi: 2020.4.5.2 installed,, 2020.4.5.2 available. Skipped Update of Package idna: 2.9 installed,, 2.9 available. Skipped Update of Package ruamel.yaml.clib: 0.2.0 installed,, 0.2.0 available. All packages are up to date! [mufit@localhost pipenv_projects]$ |
- pipenv install requests~=1.1, installs given version of a package.
- pipenv install “requests>=1.2”, installs the package equivalent to 1.2 or greater version.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
[mufit@localhost pipenv_projects]$ cat Pipfile.lock { "_meta": { "hash": { "sha256": "b777d83171c8292c32da4c85ae77b19b181188d39c8c585567e1447ea1402968" }, "pipfile-spec": 6, "requires": { "python_version": "3.6" }, "sources": [ { "name": "pypi", "url": "https://pypi.org/simple", "verify_ssl": true } ] }, "default": { "certifi": { "hashes": [ "sha256:5ad7e9a056d25ffa5082862e36f119f7f7cec6457fa07ee2f8c339814b80c9b1", "sha256:9cd41137dc19af6a5e03b630eefe7d1f458d964d406342dd3edf625839b944cc" ], "version": "==2020.4.5.2" }, "chardet": { "hashes": [ "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" ], "version": "==3.0.4" }, "idna": { "hashes": [ "sha256:7588d1c14ae4c77d74036e8c22ff447b26d0fde8f007354fd48a7814db15b7cb", "sha256:a068a21ceac8a4d63dbfd964670474107f541babbd2250d61922f029858365fa" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.9" }, "python-box": { "hashes": [ "sha256:37dcaee62446cef67ffad7baef0f1b5f541587e2064f1152ec3bc0ead64092a2", "sha256:e54aaaf5deb2dc4c0427e0ecf60415697b559c98ab21f8a6e3ae1be443445f78" ], "index": "pypi", "version": "==4.2.3" }, "requests": { "hashes": [ "sha256:b3559a131db72c33ee969480840fff4bb6dd111de7dd27c8ee1f820f4f00231b", "sha256:fe75cc94a9443b9246fc7049224f75604b113c36acb93f87b80ed42c44cbb898" ], "index": "pypi", "version": "==2.24.0" }, "ruamel.yaml": { "hashes": [ "sha256:0962fd7999e064c4865f96fb1e23079075f4a2a14849bcdc5cdba53a24f9759b", "sha256:099c644a778bf72ffa00524f78dd0b6476bca94a1da344130f4bf3381ce5b954" ], "version": "==0.16.10" }, "ruamel.yaml.clib": { "hashes": [ "sha256:1e77424825caba5553bbade750cec2277ef130647d685c2b38f68bc03453bac6", "sha256:392b7c371312abf27fb549ec2d5e0092f7ef6e6c9f767bfb13e83cb903aca0fd", "sha256:4d55386129291b96483edcb93b381470f7cd69f97585829b048a3d758d31210a", "sha256:550168c02d8de52ee58c3d8a8193d5a8a9491a5e7b2462d27ac5bf63717574c9", "sha256:57933a6986a3036257ad7bf283529e7c19c2810ff24c86f4a0cfeb49d2099919", "sha256:615b0396a7fad02d1f9a0dcf9f01202bf9caefee6265198f252c865f4227fcc6", "sha256:77556a7aa190be9a2bd83b7ee075d3df5f3c5016d395613671487e79b082d784", "sha256:7aee724e1ff424757b5bd8f6c5bbdb033a570b2b4683b17ace4dbe61a99a657b", "sha256:8073c8b92b06b572e4057b583c3d01674ceaf32167801fe545a087d7a1e8bf52", "sha256:9c6d040d0396c28d3eaaa6cb20152cb3b2f15adf35a0304f4f40a3cf9f1d2448", "sha256:a0ff786d2a7dbe55f9544b3f6ebbcc495d7e730df92a08434604f6f470b899c5", "sha256:b1b7fcee6aedcdc7e62c3a73f238b3d080c7ba6650cd808bce8d7761ec484070", "sha256:b66832ea8077d9b3f6e311c4a53d06273db5dc2db6e8a908550f3c14d67e718c", "sha256:be018933c2f4ee7de55e7bd7d0d801b3dfb09d21dad0cce8a97995fd3e44be30", "sha256:d0d3ac228c9bbab08134b4004d748cf9f8743504875b3603b3afbb97e3472947", "sha256:d10e9dd744cf85c219bf747c75194b624cc7a94f0c80ead624b06bfa9f61d3bc", "sha256:ea4362548ee0cbc266949d8a441238d9ad3600ca9910c3fe4e82ee3a50706973", "sha256:ed5b3698a2bb241b7f5cbbe277eaa7fe48b07a58784fba4f75224fd066d253ad", "sha256:f9dcc1ae73f36e8059589b601e8e4776b9976effd76c21ad6a855a74318efd6e" ], "markers": "platform_python_implementation == 'CPython' and python_version < '3.9'", "version": "==0.2.0" }, "toml": { "hashes": [ "sha256:926b612be1e5ce0634a2ca03470f95169cf16f939018233a670519cb4ac58b0f", "sha256:bda89d5935c2eac546d648028b9901107a595863cb36bae0c73ac804a9b4ce88" ], "version": "==0.10.1" }, "urllib3": { "hashes": [ "sha256:3018294ebefce6572a474f0604c2021e33b3fd8006ecd11d62107a5d2a963527", "sha256:88206b0eb87e6d677d424843ac5209e3fb9d0190d0ee169599165ec25e9d9115" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'", "version": "==1.25.9" } }, "develop": {} } [mufit@localhost pipenv_projects]$ |
Leave A Comment