oblurepip bị vô hiệu hóa trong Debian / Ubuntu cho hệ thống python


10

Tôi đang cố gắng tạo một môi trường ảo để phát triển ứng dụng Django. Bộ chỉ huy mà tôi đang sử dụng:

vagrant@vagrant:/var/www/djangogirls$ python3 -m venv myvenv
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt-get install python3-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ['/var/www/djangogirls/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']


vagrant@vagrant:/var/www/djangogirls$ sudo apt-get install python3-venv
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-venv is already the newest version (3.5.1-3).
The following packages were automatically installed and are no longer required:
  javascript-common libjs-jquery libjs-sphinxdoc libjs-underscore python-pbr python-pkg-resources
  python-six python-stevedore python3-virtualenv virtualenv virtualenv-clone
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 108 not upgraded.

vagrant@vagrant:/var/www/djangogirls$ python3 -m ensurepip
ensurepip is disabled in Debian/Ubuntu for the system python.

Python modules for the system python are usually handled by dpkg and apt-get.

    apt-get install python-<module name>

Install the python-pip package to use pip itself.  Using pip together
with the system python might have unexpected results for any system installed
module, so use it on your own risk, or make sure to only use it in virtual
environments.


vagrant@vagrant:/var/www/djangogirls$ rm -r myvenv/ 

vagrant@vagrant:/var/www/djangogirls$ python3 -m venv myvenv
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt-get install python3-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ['/var/www/djangogirls/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

Như bạn có thể thấy, tôi đang cố gắng tạo ra một myvenv, không thể tạo ra do python3-venv bị mất. Tôi đã cài đặt cái này, nhưng đảm bảo thiếu pip. Sau khi tìm kiếm, có vẻ như hệ thống (Ubuntu 16.04) không khuyến khích việc sử dụng gói. Ai đó có thể giúp tôi giải quyết vấn đề này không?


Lệnh thực tế thất bại là /var/www/djangogirls/myvenv/bin/python3 -Im ensurepip ..., có thể thất bại vì những lý do hoàn toàn khác nhau.
muru

Câu trả lời:


14

Có một báo cáo lỗi liên quan ở đây

thành phần consturepip bị thiếu / vô hiệu hóa trên Ubuntu

Cách xung quanh là tạo ra một môi trường ảo không có pip

python3 -m venv myvenv --without-pip

thành phần consturepip không được gọi và một môi trường mới được tạo ra trong trường hợp này.

Tuy nhiên thiếu pip trong môi trường ảo có thể là một vấn đề.

Một giải pháp là cài đặt gói hệ thống pip3 và sử dụng mô đun pip hệ thống bên trong môi trường ảo của bạn trực tiếp.

Môi trường ảo phải có quyền truy cập vào các gói trang web hệ thống để có thể sử dụng mô đun pip hệ thống.

  1. cài đặt hệ thống gói python3 pip

    sudo apt-get install python3-pip
  2. tạo môi trường ảo mà không cần pip và có quyền truy cập vào các gói trang web hệ thống

    python3 -m venv myvenv --without-pip --system-site-packages

Bạn có thể sử dụng mô-đun pip hệ thống để cài đặt các gói python vào môi trường ảo của bạn ngay bây giờ.

Thay vì pip install Djangobạn phải sử dụng rõ ràng

myvenv/bin/python3 -m pip install Django

hoặc bạn có thể kích hoạt môi trường ảo của bạn trước

source myvenv/bin/activate
python3 -m pip install Django

python3 -m pip --version có thể có ích để xem môi trường python được sử dụng.

Dựa trên giải pháp tìm thấy ở đây , nhưng không sử dụng đề xuất python get-pip.pytrong môi trường ảo, vì nó sẽ đánh cắp piplệnh hệ thống


Lỗi Debian cho vấn đề này là ở đây: bug.debian.org/cgi-bin/orpreport.cgi?orms=901601
nnyby

1

Anaconda không tham gia

Nếu bạn đang sử dụng Anaconda hoặc Conda , giải pháp này có thể giúp bạn:

Conda tự quản lý python như một gói , do đó, python cập nhật conda là có thể, ngược lại với pip, chỉ quản lý các gói Python. Conda có sẵn trong Anaconda và Miniconda (một bản tải xuống dễ cài đặt chỉ với Python và conda).

rất phiền cho tôi nhưng tốt, đưa tay lên bàn phím trong cửa sổ terminal:

conda update python

Nhìn vào bức ảnh này kết quả , có thể điều này giúp bạn, có một ngày tốt đẹp!

Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.