Modern Python Projects Transcripts
Chapter: Python versions and packages
Lecture: Isolate global packages with pipx
0:00 So far, we solve the problem of how to install different python versions on our
0:03 computer and how to separate dependencies,
0:07 in our project. However, there are some python packages that you would probably like
0:12 to use globally on your computer.
0:14 For example, there are some code linters like Flake 8 and pylint,
0:18 or code formatters like Black.
0:20 I will talk more about those tools in the next chapters,
0:23 or maybe even you want to install the virtualenvwrapper that we use in the
0:27 previous lessons. We wont to use those python packages across all our projects or
0:33 even outside of any project. For example,
0:36 we would use virtualenvwrapper to first,
0:38 create a virtual environment before we start coding.
0:42 Or we could use black to format,
0:43 some Random Python script. There is no point in installing those global packages inside of
0:49 a virtual environment because then to actually use it.
0:52 You would always have to first activate the virtual environment,
0:56 then run this tool, and then they activate this virtual environment.
1:00 I mean, you can do this,
1:01 but it's a lot of typing,
1:02 and generally it's a waste of your time,
1:06 a common way to install a python package globally is to just run pip install outside
1:10 of a virtual environment. This will work fine at the beginning.
1:14 But the more global packages you install,
1:17 the bigger is the chance that some of their dependencies will conflict with each other.
1:22 For example, black will install version 1 of some library,
1:26 but Flake 8 will require version 2 of this library, so it will reinstall it.
1:30 And suddenly black is no longer working and you have a mess.
1:34 It's the same situation when we try to install django 2 and django 3 in the
1:39 previous lessons. This problem can be solved with a tool called pip X,
1:44 so pipx installed spied on packages in separate environment.
1:49 But at the same time, those packages act as if they were installed globally.
1:54 You don't have to activate any virtual environment to use them.
1:59 You can install pipx with pip,
2:02 so let's run pip install pipx.
2:06 After you install pipx. Make sure you check the installation instruction from the documentation
2:11 because there is one more thing that you have to do.
2:14 We have to run 'pipx ensurepath' command.
2:19 You want to have auto-completion in your shell.
2:21 You can also run this pipx completions command.
2:24 It will show you what code do you have to add to your bash or zshell
2:28 or any other shell to make sure that auto-completion is working.
2:32 And also don't forget to restart your shell or start a new terminal for the path
2:37 changes to take effect. So let's start the new zshell session and to see if
2:42 pipx correctly installed. Let's just run pipx without any command.
2:46 Yep. If you get this list of commands,
2:48 it means everything is ready to use.