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 computer and how to separate dependencies,
0:08 in our project. However, there are some Python packages that you would probably like to use globally on your computer.
0:15 For example, there are some code linters like Flake 8 and pylint, or code formatters like Black.
0:21 I will talk more about those tools in the next chapters, or maybe even you want to install the virtualenvwrapper that we use in the
0:28 previous lessons. We wont to use those Python packages across all our projects or even outside of any project. For example,
0:37 we would use virtualenvwrapper to first, create a virtual environment before we start coding. Or we could use black to format,
0:44 some Random Python script. There is no point in installing those global packages inside of a virtual environment because then to actually use it.
0:53 You would always have to first activate the virtual environment, then run this tool, and then they activate this virtual environment.
1:01 I mean, you can do this, but it's a lot of typing, and generally it's a waste of your time,
1:07 a common way to install a Python package globally is to just run pip install outside of a virtual environment. This will work fine at the beginning.
1:15 But the more global packages you install, the bigger is the chance that some of their dependencies will conflict with each other.
1:23 For example, black will install version 1 of some library, but Flake 8 will require version 2 of this library, so it will reinstall it.
1:31 And suddenly black is no longer working and you have a mess. It's the same situation when we try to install django 2 and django 3 in the
1:40 previous lessons. This problem can be solved with a tool called pip X, so pipx installed spied on packages in separate environment.
1:50 But at the same time, those packages act as if they were installed globally. You don't have to activate any virtual environment to use them.
2:00 You can install pipx with pip, so let's run pip install pipx.
2:07 After you install pipx. Make sure you check the installation instruction from the documentation because there is one more thing that you have to do.
2:15 We have to run 'pipx ensurepath' command. You want to have auto-completion in your shell. You can also run this pipx completions command.
2:25 It will show you what code do you have to add to your bash or zshell or any other shell to make sure that auto-completion is working.
2:33 And also don't forget to restart your shell or start a new terminal for the path
2:38 changes to take effect. So let's start the new zshell session and to see if pipx correctly installed. Let's just run pipx without any command.
2:47 Yep. If you get this list of commands, it means everything is ready to use.