Don't use sudo with pip. There is a chance you'll overwrite system-installed packages, and mess up your OS.
sudo apt install <python-package> is pretty safe, but may result in outdated packages, and will definitely not include all packages you may want to install.
pip3 install <package> will install packages for just the current user (thus, not system-wide; if you're the only user, you're fine), and is what I would recommend.
Going further, virtual environment or use of Conda (an "extended" virtual environment manager) are potentially even safer, at the cost of a little more work to set up, and a bit more disk space (usually, the latter is insignificant).
You will have to read up on the use of virtual environment or Conda. That topic is too long for a standard answer here.
I would suggest as first step reading package documentation, as it often contains information regarding how to install it. Few examples regarding popular packages
Before that check to what version pertains python in your machine (by checking output of python --version), if it is Python 2 and you want to install packages to Python 3, then you need to use pip3 and python3 rather than pip and python, if it is Python 3 you might use command as they are.
发布评论
评论(2)
不要将
sudo
与pip
一起使用。您有可能覆盖系统安装的软件包,然后弄乱您的操作系统。sudo apt install&lt; python-package&gt;
非常安全,但可能会导致过时的软件包,并且绝对不会包括您可能想要安装的所有软件包。pip3 install&lt; package&gt;
将仅为当前用户安装软件包(因此,不在系统范围内;如果您是唯一的用户,那么您就可以了),这是我建议的。进一步,虚拟环境或使用conda(“扩展”虚拟环境管理器)甚至可能更安全,而要花费更多的工作来设置,还有更多的磁盘空间(通常,后者无关紧要)。
您将不得不阅读使用虚拟环境或CONDA的使用。这个主题在这里有标准答案太长。
Don't use
sudo
withpip
. There is a chance you'll overwrite system-installed packages, and mess up your OS.sudo apt install <python-package>
is pretty safe, but may result in outdated packages, and will definitely not include all packages you may want to install.pip3 install <package>
will install packages for just the current user (thus, not system-wide; if you're the only user, you're fine), and is what I would recommend.Going further, virtual environment or use of Conda (an "extended" virtual environment manager) are potentially even safer, at the cost of a little more work to set up, and a bit more disk space (usually, the latter is insignificant).
You will have to read up on the use of virtual environment or Conda. That topic is too long for a standard answer here.
我建议作为第一步阅读包文档,因为它通常包含有关如何安装它的信息。 的几个示例
jinja2
建议
pip install jinja2
请求
建议python -m pip安装请求
在您的计算机中检查到哪个版本
python
(通过检查python的输出 - - version
),如果是python 2,并且要将软件包安装到python 3,则需要使用pip3
和python3
而不是pip
和python
,如果是python 3,则可以按照命令来使用命令。I would suggest as first step reading package documentation, as it often contains information regarding how to install it. Few examples regarding popular packages
click
suggestspip install click
jinja2
suggestspip install Jinja2
requests
suggestspython -m pip install requests
Before that check to what version pertains
python
in your machine (by checking output ofpython --version
), if it is Python 2 and you want to install packages to Python 3, then you need to usepip3
andpython3
rather thanpip
andpython
, if it is Python 3 you might use command as they are.