Nice programing

python setup.py 제거

nicepro 2020. 9. 29. 18:42
반응형

python setup.py 제거


.NET Framework와 함께 python 패키지를 설치했습니다 python setup.py install.

어떻게 제거합니까?


참고 : 사용하지 마십시오 python setup.py install사용pip install .

모든 파일을 수동으로 제거하고 설치에서 수동으로 수행 한 다른 작업도 실행 취소해야합니다.

모든 파일 목록을 모르는 경우 --record옵션을 사용하여 다시 설치하고 생성 된 목록을 살펴볼 수 있습니다.

설치된 파일 목록을 기록하려면 다음을 사용할 수 있습니다.

python setup.py install --record files.txt

제거하려면 xargs를 사용하여 제거 할 수 있습니다.

xargs rm -rf < files.txt

또는 Windows를 실행중인 경우 Powershell을 사용합니다.

Get-Content files.txt | ForEach-Object {Remove-Item $_ -Recurse -Force}

그런 다음 포함하는 디렉토리도 삭제합니다 (예 : /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/my_module-0.1.egg/on) macOS. 파일이 없지만 Python은 여전히 ​​빈 모듈을 가져옵니다.

>>> import my_module
>>> my_module.__file__
None

삭제되면 Python은 다음을 표시합니다.

>>> import my_module
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'my_module'

나를 위해 다음은 대부분 작동합니다.

pip가 설치되어 있어야합니다. 예 :

$ easy_install pip

pip 관점에서 설치된 패키지 이름이 어떻게 지정되었는지 확인하십시오.

$ pip freeze

여기에는 설치 한 (그리고 pip에 의해 감지 된) 모든 패키지의 이름이 나열됩니다. 이름은 어느 정도 길 수 있으며 다음에 표시되는 패키지의 이름 만 사용할 수 있습니다 #egg=. 또한 대부분의 경우 버전 부분을 무시할 수 있습니다 ( ==또는 뒤에 오는 항목 -).

그런 다음 패키지를 제거합니다.

$ pip uninstall package.name.you.have.found

패키지 제거에 대한 확인을 요청하면 운이 좋은 사람이며 제거됩니다.

pip는 pip에 의해 설치된 모든 패키지를 감지합니다. 또한 easy_install 또는 setup.py를 통해 설치된 대부분의 패키지를 감지하지만 드물게 실패 할 수 있습니다.

다음은 ttr.rdstmcMS Windows에서 이름이 지정된 패키지를 사용한 로컬 테스트의 실제 샘플입니다 .

$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
ttr.utcutils==0.1.1dev

$ python setup.py develop
.....
.....
Finished processing dependencies for ttr.rdstmc==0.0.1dev

$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
-e hg+https://vlcinsky@bitbucket.org/vlcinsky/ttr.rdstmc@d61a9922920c508862602f7f39e496f7b99315f0#egg=ttr.rdstmc-dev
ttr.utcutils==0.1.1dev

$ pip uninstall ttr.rdstmc
Uninstalling ttr.rdstmc:
  c:\python27\lib\site-packages\ttr.rdstmc.egg-link
Proceed (y/n)? y
  Successfully uninstalled ttr.rdstmc

$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
ttr.utcutils==0.1.1dev

2015-05-20 수정

All what is written above still applies, anyway, there are small modifications available now.

Install pip in python 2.7.9 and python 3.4

Recent python versions come with a package ensurepip allowing to install pip even when being offline:

$ python -m ensurepip --upgrade

On some systems (like Debian Jessie) this is not available (to prevent breaking system python installation).

Using grep or find

Examples above assume, you have grep installed. I had (at the time I had MS Windows on my machine) installed set of linux utilities (incl. grep). Alternatively, use native MS Windows find or simply ignore that filtering and find the name in a bit longer list of detected python packages.


The #1 answer has problems:

  • Won't work on mac.
  • If a file is installed which includes spaces or other special characters, the xargs command will fail, and delete any files/directories which matched the individual words.
  • the -r in rm -rf is unnecessary and at worst could delete things you don't want to.

Instead, for unix-like:

sudo python setup.py install --record files.txt
# inspect files.txt to make sure it looks ok. Then:
tr '\n' '\0' < files.txt | xargs -0 sudo rm -f --

And for windows:

python setup.py bdist_wininst
dist/foo-1.0.win32.exe

There are also unsolvable problems with uninstalling setup.py install which won't bother you in a typical case. For a more complete answer, see this wiki page:

https://ofswiki.org/wiki/Uninstalling_setup.py_install


First record the files you have installed. You can repeat this command, even if you have previously run setup.py install:

python setup.py install --record files.txt

When you want to uninstall you can just:

sudo rm $(cat files.txt)

This works because the rm command takes a whitespace-seperated list of files to delete and your installation record is just such a list.


Now python gives you the choice to install pip during the installation (I am on Windows, and at least python does so for Windows!). Considering you had chosen to install pip during installation of python (you don't actually have to choose because it is default), pip is already installed for you. Then, type in pip in command prompt, you should see a help come up. You can find necessary usage instructions there. E.g. pip list shows you the list of installed packages. You can use

pip uninstall package_name

to uninstall any package that you don't want anymore. Read more here (pip documentation).


The lazy way: simply uninstall from the Windows installation menu (if you're using Windows), or from the rpm command, provided you first re-install it after creating a distribution package.

For example,

python setup.py bdist_wininst
dist/foo-1.0.win32.exe

("foo" being an example of course).


Go to your python package directory and remove your .egg file, e.g.: In python 2.5(ubuntu): /usr/lib/python2.5/site-packages/

In python 2.6(ubuntu): /usr/local/lib/python2.6/dist-packages/


Probably you can do this as an alternative :-

1) Get the python version -

[linux machine]# python
Python 2.4.3 (#1, Jun 18 2012, 14:38:55) 

-> The above command gives you the current python Version which is 2.4.3

2) Get the installation directory of python -

[linux machine]# whereis python
python: /usr/bin/python /usr/bin/python2.4 /usr/lib/python2.4 /usr/local/bin/python2.5 /usr/include/python2.4 /usr/share/man/man1/python.1.gz

-> From above command you can get the installation directory which is - /usr/lib/python2.4/site-packages

3) From here you can remove the packages and python egg files

[linux machine]# cd /usr/lib/python2.4/site-packages
[linux machine]# rm -rf paramiko-1.12.0-py2.4.egg paramiko-1.7.7.1-py2.4.egg paramiko-1.9.0-py2.4.egg

This worked for me.. And i was able to uninstall package which was troubling me :)


I think you can open the setup.py, locate the package name, and then ask pip to uninstall it.

Assuming the name is available in a 'METADATA' variable:

pip uninstall $(python -c "from setup import METADATA; print METADATA['name']")

Not exactly answering the question, but something that helps me every day:

Install your packages with

pip install .

This puts the package in $HOME/.local. Uninstall with

pip uninstall <package_name>

Extending on what Martin said, recording the install output and a little bash scripting does the trick quite nicely. Here's what I do...

for i in $(less install.record);
sudo rm $i;
done;

And presto. Uninstalled.


I had run "python setup.py install" at some point in the past accidentally in my global environment, and had much difficulty uninstalling. These solutions didn't help. "pip uninstall " didn't work with "Can't uninstall 'splunk-appinspect'. No files were found to uninstall." "sudo pip uninstall " didn't work "Cannot uninstall requirement splunk-appinspect, not installed". I tried uninstalling pip, deleting the pip cache, searching my hard drive for the package, etc...

"pip show " eventually led me to the solution, the "Location:" was pointing to a directory, and renaming that directory caused the packaged to be removed from pip's list. I renamed the directory back, and it didn't reappear in pip's list, and now I can reinstall my package in a virtualenv.


I had run python setup.py install once in my PyCharm, it installs all the packages into my conda base environment. Later when I want to remove all these packages, pip uninstall does not work. I had to delete them from /anaconda3/lib/python3.7/site-packages manually :(

So I don't see the reason why they use setup.py instead of writing requirements.txt file. The requirement file can be used to install packages in virtual environment and won't mess with system python packages.


If you still have files that are supposed to be deleted after re-installing a package, make sure the folder build is also deleted. Therefore, assuming that pkg is the package you want to delete:

rm -r $(python3 -c "import pkg; print(pkg.__path__[0] + '*' )") 
rm -rf build

Obove work out for python3 and delete the package and its *.egg-info file


At {virtualenv}/lib/python2.7/site-packages/ (if not using virtualenv then {system_dir}/lib/python2.7/dist-packages/)

  • Remove the egg file (e.g. distribute-0.6.34-py2.7.egg)
  • If there is any from file easy-install.pth, remove the corresponding line (it should be a path to the source directory or of an egg file).

It might be better to remove related files by using bash to read commands, like the following:

sudo python setup.py install --record files.txt
sudo bash -c "cat files.txt | xargs rm -rf"

참고URL : https://stackoverflow.com/questions/1550226/python-setup-py-uninstall

반응형