python - 文件位置和用法 : apt-get install python-<pkg> vs. pip3 install <pkg>

标签 python ubuntu pip apt

我发现 sudo apt-get install python-<pkg>sudo pip3 install <pkg>在不同的地方安装文件。

有没有办法通过对用户透明的两个选项中的任何一个来渲染安装?

在我的特殊情况下,它不是,见下文。 apt-get 安装的二进制文件被 pip3 删除,所以它的用法是不同的。

副产品问题是:

依次为:1)apt-get install,2)pip --upgrade,第二步升级版本,修改文件位置。但是apt-get仍然认为它有它的原始版本,在原始位置。
如何解决这个问题?

我的意思是安装virtualenv .
我刚刚做了以下事情:

  • 安装 python-virtualenv
    $ sudo apt-get install python-virtualenv
    Reading package lists... Done
    ...
    Setting up virtualenv (15.0.1+ds-3ubuntu1) ...
    
  • 检查 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
    
  • 查找安装了哪些文件。这些在 /usr/lib/python3/dist-packages , 和 pip3明白这一 pip 。
    $ 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
    
  • 查找版本
    $ virtualenv --version
    15.0.1
    
  • 使用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.
    

  • 所以这运作良好。
    现在我所做的是:
  • 升级到最新版本。这必须通过 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
    
  • 尝试使用 virtualenv
    $ virtualenv -p python3 my_project
    bash: /usr/bin/virtualenv: No such file or directory
    
  • 查找安装了哪些文件。 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
    
  • 尝试恢复 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.
    
  • 最佳答案

    通常,使用 apt 升级使用系统包管理器(在本例中为 pip)安装的包不是一个好主意。因为它们将不再受系统管理。
    pip将安装到 /usr/local .在您的 shell 中找不到您的命令的原因是 command hashing .您可以运行 hash -r你就可以使用virtualenv ...再次(来自 /usr/local/bin/virtualenv)

    原因apt相信virtualenv仍然安装是因为你没有用 apt 卸载它.通过 pip 升级不会更新 dpkg元数据。您可以使用 grep 验证这一 pip :

    # 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
    

    关于python - 文件位置和用法 : apt-get install python-<pkg> vs. pip3 install <pkg>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43567007/

    相关文章:

    linux - 安装Ubuntu后无法启动计算机

    git clone over https 401 错误,不要求输入用户名或密码

    python - pip install sqlalchemy-migrate 莫名崩溃烧毁

    python - 如何更改 PIP 的安装路径

    python - 在 Bluehost 上安装 pip

    Python 查找区间的连续交集

    python - Pandas :通过第一次和最后一次出现来填充每一行

    python - 在执行期间更改 Spark Streaming 中的批量大小

    python - 如何在Python中创建具有两列作为元组或Pandas数据框的单个变量?

    mysql - SQL 客户端抛出错误 1045 但我可以通过命令行进入?