简体   繁体   English

文件的位置和用法:apt-get install python- <pkg> 与pip3安装 <pkg>

[英]Location of files and usage: apt-get install python-<pkg> vs. pip3 install <pkg>

I found that sudo apt-get install python-<pkg> and sudo pip3 install <pkg> install files in different places. 我发现sudo apt-get install python-<pkg>sudo pip3 install <pkg>安装文件在不同的位置。

Is there any way of rendering installation via any of the two options transparent to the user? 是否可以通过两个选项中的任何一个对用户透明的方式呈现安装?

In my particular case, it was not, see below. 在我的特定情况下,不是,请参见下文。 The binary installed by apt-get is removed by pip3 , so its usage is different. apt-get安装的二进制文件已被pip3删除,因此其用法有所不同。

Byproduct questions are: 副产品问题是:

In the sequence: 1) apt-get install, 2) pip --upgrade, the second step upgrades version and changes files location. 按照以下顺序:1)apt-get install,2)pip --upgrade,第二步升级版本并更改文件位置。 But apt-get still thinks it has its original version, at the original location. 但是apt-get仍然认为它在原始位置具有原始版本。 How can this be fixed? 如何解决?

I meant to install virtualenv . 我打算安装virtualenv I have just done the following: 我刚刚做了以下工作:

  1. Install python-virtualenv 安装python-virtualenv

     $ sudo apt-get install python-virtualenv Reading package lists... Done ... Setting up virtualenv (15.0.1+ds-3ubuntu1) ... 
  2. Check that pip3 reads virtualenv 检查pip3读取virtualenv

     $ sudo pip3 install virtualenv The directory '/home/santiago/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/home/santiago/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Requirement already satisfied: virtualenv in /usr/lib/python3/dist-packages 
  3. Find which files were installed. 查找已安装的文件。 These are in /usr/lib/python3/dist-packages , and pip3 understands this. 这些位于/usr/lib/python3/dist-packagespip3理解这一点。

     $ ll /usr/lib/python3/dist-packages/virtualenv* -rw-r--r-- 1 root root 100655 Nov 30 08:29 /usr/lib/python3/dist-packages/virtualenv.py /usr/lib/python3/dist-packages/virtualenv-15.0.1.egg-info: total 36 drwxr-xr-x 2 root root 4096 Apr 22 20:48 ./ drwxr-xr-x 146 root root 12288 Apr 22 20:48 ../ -rw-r--r-- 1 root root 1 Nov 30 08:29 dependency_links.txt -rw-r--r-- 1 root root 48 Nov 30 08:29 entry_points.txt -rw-r--r-- 1 root root 1 Nov 30 08:29 not-zip-safe -rw-r--r-- 1 root root 3409 Nov 30 08:29 PKG-INFO -rw-r--r-- 1 root root 11 Nov 30 08:29 top_level.txt 
  4. Find the version 查找版本

     $ virtualenv --version 15.0.1 
  5. Use virtualenv 使用virtualenv

     $ virtualenv my_project Running virtualenv with interpreter /usr/bin/python2 New python executable in /home/santiago/my_project/bin/python2 Also creating executable in /home/santiago/my_project/bin/python Installing setuptools, pkg_resources, pip, wheel...done. 

So this was working well. 所以这很好。 Now what I did is: 现在我要做的是:

  1. Upgrade to the latest version. 升级到最新版本。 This had to be done with pip , since apt-get installed its latest available version. 这必须使用pip完成,因为apt-get安装了其最新可用版本。

     $ sudo pip3 install --upgrade virtualenv [sudo] password for santiago: The directory '/home/santiago/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/home/santiago/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Collecting virtualenv Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB) 100% |████████████████████████████████| 1.8MB 781kB/s Installing collected packages: virtualenv Found existing installation: virtualenv 15.0.1 Uninstalling virtualenv-15.0.1: Successfully uninstalled virtualenv-15.0.1 Successfully installed virtualenv-15.1.0 
  2. Try using virtualenv 尝试使用virtualenv

     $ virtualenv -p python3 my_project bash: /usr/bin/virtualenv: No such file or directory 
  3. Find which files were installed. 查找已安装的文件。 The files installed by apt-get are gone. apt-get安装的文件不见了。

     $ ll /usr/lib/python3/dist-packages/virtualenv* ls: cannot access '/usr/lib/python3/dist-packages/virtualenv*': No such file or directory $ ll /usr/bin/virtualenv ll /usr/bin/virtualenv 
  4. Try recovering what apt-get gave. 尝试恢复apt-get提供的内容。

     $ sudo apt-get install python-virtualenv Reading package lists... Done Building dependency tree Reading state information... Done python-virtualenv is already the newest version (15.0.1+ds-3ubuntu1). The following packages were automatically installed and are no longer required: linux-headers-4.4.0-64 linux-headers-4.4.0-64-generic linux-image-4.4.0-64-generic linux-image-extra-4.4.0-64-generic Use 'sudo apt autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 174 not upgraded. 

Generally it's not a good idea to upgrade package installed with the system package manager ( apt in this case) with pip as they will no longer be managed by the system. 通常,用pip升级系统软件包管理器(在本例中为apt )安装的软件包不是一个好主意,因为它们将不再由系统管理。

pip will install into /usr/local . pip将安装到/usr/local The reason your command was not found in your shell is due to command hashing . 在外壳程序中找不到命令的原因是由于命令哈希 You can run hash -r and you'll be able to use virtualenv ... again (from /usr/local/bin/virtualenv ) 您可以运行hash -r然后可以再次使用virtualenv ... (从/usr/local/bin/virtualenv

The reason apt believes that virtualenv is still installed is because you have not uninstalled it with apt . apt认为仍然安装了virtualenv的原因是因为尚未使用apt 卸载它。 An upgrade via pip does not update the dpkg metadata. 通过pip升级不会更新dpkg元数据。 You can verify this with grep: 您可以使用grep进行验证:

# Note: I'm using xenial, if you're on something ealier the package will
# just be called `python-virtualenv` or `python3-virtualenv`
$ grep -C1 '^Package: virtualenv$' /var/lib/dpkg/status

Package: virtualenv
Status: install ok installed
$ grep -C1 '^Package: python3-virtualenv$' /var/lib/dpkg/status

Package: python3-virtualenv
Status: install ok installed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 apt-get install python文件还是只是pip install? - apt-get install python files or just pip install? 通过 Ubuntu 的 apt-get 在 Dockerfile 中使用 apt-get 安装 python-pip - Install python-pip using apt-get via Ubuntu's apt-get in Dockerfile 尝试通过“ pip install”安装Scitools Python pkg,但出现错误 - Trying to install a Scitools Python pkg via 'pip install' but getting error 不同python版本的apt-get安装 - apt-get install for different python versions python3 -m pip install VS pip3 install - python3 -m pip install VS pip3 install 无法使用 apt-get install python-pip 在kali linux 2019.3 vbox amd 64 中安装 python-pip - Not able to install python-pip in kali linux 2019.3 vbox amd 64 with apt-get install python-pip pip 安装 matplotlib:“没有 pkg​​-config” - pip install matplotlib: "no pkg-config" pip 安装不工作。 无法从“pip._vendor.pkg_resources”(未知位置)导入名称“Requirement” - pip install is not working. cannot import name 'Requirement' from 'pip._vendor.pkg_resources' (unknown location) Python- pip安装googleplaces - Python- pip install googleplaces sudo pip3 install pygame 和 sudo apt install python3-pygame 有什么区别 - What is the difference between sudo pip3 install pygame and sudo apt install python3-pygame
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM