본문 바로가기

Python

[python] 가상환경 venv 생성시 나타나는 The virtual environment was not created successfully 에러 해결법

반응형

 

 

파이썬에서 특정 버전의 가상 환경을 설치할 때 아래와 같은 에러 메시지가 발생할 때가 있다.

 

# python3.7 -m venv venv
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: ['/root/fss-data/venv/bin/python3.7', '-Im', 'ensurepip', '--upgrade', '--default-pip']

 

문제는 가이드한 대로 python3-venv를 설치해도 똑같은 에러 메시지가 나온다.

 

위 문제는 venv를 설치할때 python 버전을 명확히 정해주면 해결이 된다.

 

# apt-get install python3.7-venv
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  python3.7-venv
0 upgraded, 1 newly installed, 0 to remove and 192 not upgraded.
Need to get 6,188 B of archives.
After this operation, 32.8 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 python3.7-venv amd64 3.7.5-2~18.04.4 [6,188 B]
Fetched 6,188 B in 0s (14.9 kB/s)          
Selecting previously unselected package python3.7-venv.
(Reading database ... 77166 files and directories currently installed.)
Preparing to unpack .../python3.7-venv_3.7.5-2~18.04.4_amd64.deb ...
Unpacking python3.7-venv (3.7.5-2~18.04.4) ...
Setting up python3.7-venv (3.7.5-2~18.04.4) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

 

 

확인해보면 성공적으로 가상환경이 생성된 것을 알 수 있다.

 

# python3.7 -m venv venv
root@vultr:~/fss-data# ls -al
total 16
drwxr-xr-x  3 root root 4096 Dec 12 05:53 .
drwx------ 11 root root 4096 Dec 12 05:51 ..
-rw-r--r--  1 root root  535 Dec 12 05:50 test.py
drwxr-xr-x  6 root root 4096 Dec 12 05:56 venv



# . venv/bin/activate
(venv) root@vultr:~/fss-data#

 

반응형