Using pip3 install, local vs. global
If you're using sudo with pip3 command, package will install to /usr/local/bin/mysqlclient
directory which will be accessed by all users(i.e. installing globally).
Whereas, without sudo it will install to ~/.local/bin/mysqlclient
directory and only access current user(i.e. installing locally).
But, try to prefer virtual environments to create an isolated environment for Python projects. This means that each project can have its own dependencies, regardless of what dependencies every other project has. It's handy for large sized projects.
You only use sudo
or elevated permissions when you want to install stuff for the global, systemwide Python installation with pip
or pip3
. Otherwise install python packages locally with pip3 install --user <package>
(e.g. pip3 install --user mysqlclient
).
Malicious packages are occasionally found on PyPI, the official third-party repository for software for the Python programming language. It is best to use a Python virtual environment to isolate packages that you install with pip/pip3. The virtualenv utility creates virtual Python instances, each invokable with its own Python executable. Each instance can have different sets of modules. Virtual Python instances can also be created without root access.