티스토리 뷰

개발/파이썬

virtualenv에서 Python 3 사용

맨날치킨 2022. 11. 25. 20:35
반응형

Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.

Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.

 

아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.

Using Python 3 in virtualenv

virtualenv에서 Python 3 사용

 문제 내용 

Using virtualenv, I run my projects with the default version of Python (2.7). On one project, I need to use Python 3.4.

virtualenv를 사용하여 기본 버전의 Python(2.7)으로 프로젝트를 실행합니다. 한 프로젝트에서 나는 파이썬 3.4를 사용해야 한다.

 

I used brew install python3 to install it on my Mac. Now, how do I create a virtualenv that uses the new version?

나는 brew install python3를 사용하여 맥에 설치했다. 이제 새 버전을 사용하는 가상 env를 생성하려면 어떻게 해야 합니까?

 

e.g. sudo virtualenv envPython3

예: sudo virtual env env Python3

 

If I try:

시도하면:

 

virtualenv -p python3 test

I get:

아래 오류를 받습니다:

 

Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python3/3.4.0_1/Frameworks/Python.framework/Versions/3.4'
New python executable in test/bin/python3.4
Also creating executable in test/bin/python
Failed to import the site module
Traceback (most recent call last):
  File "/Users/user/Documents/workspace/test/test/bin/../lib/python3.4/site.py", line 67, in <module>
    import os
  File "/Users/user/Documents/workspace/test/test/bin/../lib/python3.4/os.py", line 634, in <module>
    from _collections_abc import MutableMapping
ImportError: No module named '_collections_abc'
ERROR: The executable test/bin/python3.4 is not functioning
ERROR: It thinks sys.prefix is '/Users/user/Documents/workspace/test' (should be '/Users/user/Documents/workspace/test/test')
ERROR: virtualenv is not compatible with this system or executable

 

 

 높은 점수를 받은 Solution 

simply run

간단히 실행하세요.

 

virtualenv -p python3 envname

Update after OP's edit:

OP의 편집 후 업데이트:

 

There was a bug in the OP's version of virtualenv, as described here. The problem was fixed by running:

여기에 설명된 바와 같이 OP의 virtualenv 버전에 버그가 있었습니다. 이 문제는 다음을 실행하여 해결되었습니다.

 

pip install --upgrade virtualenv

 

 

 가장 최근 달린 Solution 

The below simple commands can create a virtual env with version 3.5

아래의 간단한 명령은 버전 3.5의 가상 env를 생성할 수 있습니다.

 

apt-get install python3-venv

python3.5 -m venv <your env name>

if you want virtual env version as 3.6

가상 env 버전을 3.6으로 지정하려는 경우

 

python3.6 -m venv <your env name>

 

 

출처 : https://stackoverflow.com/questions/23842713/using-python-3-in-virtualenv

반응형
댓글
공지사항
최근에 올라온 글