Virtualenvs의 깨진 참조
최근에 다른 응용 프로그램과 함께 Mac에 많은 도트 파일을 설치했습니다 (터미널 대신 iTerm으로 변경하고 기본 텍스트 편집기로 Sublime로 변경했습니다). 여전히 거기에 있고 아무것도 실행하려고 할 때마다 다음과 같은 오류가 발생합니다.
dyld: Library not loaded: @executable_path/../.Python
Referenced from: /Users/[user]/.virtualenvs/modclass/bin/python
Reason: image not found
Trace/BPT trap: 5
dotfile과 관련된 모든 파일을 제거하고 .bash_profile을 이전 상태로 복원했지만 문제가 지속됩니다. 문제를 진단하거나 쉽게 해결할 수있는 방법이 있습니까 (예 : 모든 가상 환경을 다시 만들 필요가 없음)?
여기서 문제에 대한 해결책을 찾았 으므로 모든 크레딧은 저자에게 전달됩니다.
요점은 virtualenv를 만들 때 Homebrew가 설치된 Python에 많은 심볼릭 링크가 만들어지는 것입니다.
다음은 하나의 예입니다.
$ ls -la ~/.virtualenvs/my-virtual-env
...
lrwxr-xr-x 1 ryan staff 78 Jun 25 13:21 .Python -> /usr/local/Cellar/python/2.7.7/Frameworks/Python.framework/Versions/2.7/Python
...
Homebrew를 사용하여 Python을 업그레이드 한 다음을 실행 brew cleanup
하면 virtualenv의 심볼릭 링크가 더 이상 존재하지 않는 경로를 가리 킵니다 (Homebrew가 삭제했기 때문에).
심볼릭 링크는 새로 설치된 Python을 가리켜 야합니다.
lrwxr-xr-x 1 ryan staff 78 Jun 25 13:21 .Python -> /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/Python
해결책은 virtualenv에서 심볼릭 링크를 제거한 다음 다시 만드는 것입니다.
find ~/.virtualenvs/my-virtual-env/ -type l -delete
virtualenv ~/.virtualenvs/my-virtual-env
삭제하기 전에 어떤 링크가 먼저 삭제되는지 확인하는 것이 가장 좋습니다.
find ~/.virtualenvs/my-virtual-env/ -type l
제 생각에는 깨진 심볼릭 링크 만 삭제하는 것이 좋습니다. GNU를 사용하여이 작업을 수행 할 수 있습니다 find
.
gfind ~/.virtualenvs/my-virtual-env/ -type l -xtype l -delete
GNU find
가없는 경우 Homebrew와 함께 GNU 를 설치할 수 있습니다 .
brew install findutils
기본적으로 Homebrew와 함께 설치된 GNU 프로그램은 접두사가 붙는 경향이 있습니다 g
. 이것은 find
OS X와 함께 제공 되는 바이너리를 가리지 않도록하기위한 것 입니다.
몇 가지를 시도한 후에 이것은 나를 위해 일했습니다.
virtualenv 디렉토리로 이동하십시오 (그러나 workon을 실행하지 마십시오).
cd ~/.virtualenv/name_of_broken_venv
이제이 파일들을 삭제하십시오 :
rm -rf .Python bin/python* lib/python2.7/* include/python2.7
그런 다음 venv를 다시 빌드하려면 다음을 실행하십시오.
virtualenv .
workon name_of_broken_venv
pip freeze
이제 설치된 패키지 목록이 다시 나타납니다.
Snow Leopard에서 Mac OS X Mavericks로 업데이트했을 때 발생했습니다. 사전에 추출을 다시 설치해야했습니다. pip를 사용하여 프로젝트에 대한 고정 명령을 실행했으면합니다.
해결하려면 가상 환경이 가리키는 경로를 업데이트해야합니다.
- brew로 python 버전을 설치하십시오.
brew install python
- virtualenvwrapper를 다시 설치하십시오.
pip install --upgrade virtualenvwrapper
- 이전 가상 환경을 제거했습니다.
rmvirtualenv old_project
- 새로운 가상 환경을 만듭니다.
mkvirtualenv new_project
- 새로운 가상 환경에서 작업
workon new_project
- Use pip to install the requirements for the new project.
pip install -r requirements.txt
This should leave the project as it was before.
It appears the proper way to resolve this issue is to run
pip install --upgrade virtualenv
after you have upgraded python with Homebrew.
This should be a general procedure for any formula that installs something like python, which has it's own package management system. When you install brew install python
, you install python
and pip
and easy_install
and virtualenv
and so on. So, if those tools can be self-updated, it's best to try to do so before looking to Homebrew as the source of problems.
A update version @Chris Wedgwood
's answer for keeping site-packages
(keeping packages installed)
cd ~/.virtualenv/name_of_broken_venv
mv lib/python2.7/site-packages ./
rm -rf .Python bin lib include
virtualenv .
rm -rf lib/python2.7/site-packages
mv ./site-packages lib/python2.7/
If this was caused by a brew upgrade
that upgraded its Python, and you're ok with downgrading to the previous version, try brew switch python [previous version]
, eg brew switch python 3.6.5
. From here.
If you've busted python3 just try brew upgrade python3
that fixed it for me.
I recently faced this. None of the above solutions worked for me. Seems it wasn't actually Python's problem. When I was running
aws s3 ls
I was getting following error:
dyld: Library not loaded: @executable_path/../.Python
This means, the library aws
executable is pointing towards is either doesn't exist or is corrupted, thus I uninstalled and reinstalled aws-cli
following instructions from this link and it worked!!
virtualenvwrapper instructions
As indicated in the accepted answer, the root cause is likely a homebrew update that means your virtualenv symlinks are pointing at broken python paths - see details here.
For each virtual env, you need to reassign the symlinks to point at the correct python path (in brew cellar). Here is how to do it with virtualenvwrapper. Here I am updating a virtual env called "my-example-env".
cd ~/PYTHON_ENVS
find ./my-example-env -type l -delete
mkvirtualenv my-example-env
All done.
Using Python 2.7.10.
A single command virtualenv path-to-env
does it. documentation
$ virtualenv path-to-env
Overwriting path-to-env/lib/python2.7/orig-prefix.txt with new content
New python executable in path-to-env/bin/python2.7
Also creating executable in path-to-env/bin/python
Installing setuptools, pip, wheel...done.
The problem for me(a MacOS user) is that brew
updated the Python and virtualenvs links to the old version which was deleted.
We can check and fix it by
>> ls -al ~/.virtualenvs/<your-virtual-env>/.Python
.Python -> /usr/local/Cellar/python/<old-version>/Frameworks/Python.framework/Versions/3.7/Python
>> rm ~/.virtualenvs/<your-virtual-env>/.Python
>> ln -s /usr/local/Cellar/python/<new-version>/Frameworks/Python.framework/Versions/3.7/Python ~/.virtualenvs/<your-virtual-env>/.Python
Anyone who is using pipenv (and you should!) can simply use these two commands — without having the venv activated:
rm -rf `pipenv --venv` # remove the broken venv
pipenv install --dev # reinstall the venv from pipfile
The accepted answer does not work for me: the file $WORKON_HOME/*/bin/python2.7
is no longer a symlink, it is a full-fledged executable:
$ file $WORKON_HOME/*/bin/python2.7
/Users/sds/.virtualenvs/.../bin/python2.7: Mach-O 64-bit executable x86_64
...
The solution is, alas, to completely remove and re-create from scratch all the virtual environments.
For the reference:
deactivate
pip install --user virtualenv virtualenvwrapper
pip install --user --upgrade virtualenv virtualenvwrapper
for ve in $(lsvirtualenv -b); do
# assume that each VE is associated with a project
# and the project has the requirements.txt file
project=$(cat $WORKON_HOME/$ve/.project)
rmvirtualenv $ve
mkvirtualenv -a $project -r requirements.txt $ve
done
Simply upgrading python3 worked for me:
brew upgrade python3
I tried the top few methods, but they didn't work, for me, which were trying to make tox work. What eventually worked was:
sudo pip install tox
even if tox was already installed. The output terminated with:
Successfully built filelock
Installing collected packages: py, pluggy, toml, filelock, tox
Successfully installed filelock-3.0.10 pluggy-0.11.0 py-1.8.0 toml-0.10.0 tox-3.9.0
What fixed it for me was just uninstalling python3 and pipenv then reinstalling them.
brew uninstall pipenv
brew uninstall python3
brew install python3
brew install pipenv
I had a broken virtual env due to a Homebrew reinstall of python (thereby broken symlinks) and also a few "sudo pip install"s I had done earlier. Weizhong's tips were very helpful in fixing the issues without having to reinstall packages. I also had to do the following for the mixed permissions problem.
sudo chown -R my_username lib/python2.7/site-packages
Virtualenvs are broken. Sometimes simple way is to delete venv folders and recreate virutalenvs.
참고URL : https://stackoverflow.com/questions/23233252/broken-references-in-virtualenvs
'Programing' 카테고리의 다른 글
반복하는 동안 컬렉션에서 요소 제거 (0) | 2020.05.15 |
---|---|
파일의 시작 부분에 텍스트를 삽입하는 방법? (0) | 2020.05.15 |
TaskCompletionSource는 언제해야합니까 (0) | 2020.05.15 |
(Java) 패키지 구성에 대한 모범 사례가 있습니까? (0) | 2020.05.15 |
Xcode : 일반 언어로 된 목표와 체계는 무엇입니까? (0) | 2020.05.15 |