🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 问题 You want to install a third-party package, but you don’t have permission to install packagesinto the system Python. Alternatively, perhaps you just want to install a packagefor your own use, not all users on the system. ## 解决方案 Python has a per-user installation directory that’s typically located in a directory suchas ~/.local/lib/python3.3/site-packages. To force packages to install in this directory, givethe –user option to the installation command. For example: python3 setup.py install --user or pip install --user packagename The user site-packages directory normally appears before the system site-packages directoryon sys.path. Thus, packages you install using this technique take priority overthe packages already installed on the system (although this is not always the case dependingon the behavior of third-party package managers, such as distribute or pip). ## 讨论 Normally, packages get installed into the system-wide site-packages directory, which isfound in a location such as /usr/local/lib/python3.3/site-packages. However, doing sotypically requires administrator permissions and use of the sudo command. Even if youhave permission to execute such a command, using sudo to install a new, possibly unproven,package might give you some pause. Installing packages into the per-user directory is often an effective workaround thatallows you to create a custom installation. As an alternative, you can also create a virtual environment, which is discussed in thenext recipe.