执行python setup.py install时报错:error: can't create or remove files in install directory

我会带着你远行 2023-07-03 04:34 111阅读 0赞

文章目录

    • 报错
    • mac&linux
    • Windows

报错

在研究setuptools时,执行python setup.py install,遇到不能创建文件夹的权限报错,完整的错误日志如下:

  1. ~ python setup.py install
  2. running install
  3. error: can't create or remove files in install directory
  4. The following error occurred while trying to add or remove files in the
  5. installation directory:
  6. [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-19811.write-test'
  7. The installation directory you specified (via --install-dir, --prefix, or
  8. the distutils default setting) was:
  9. /Library/Python/2.7/site-packages/
  10. Perhaps your account does not have write access to this directory? If the
  11. installation directory is a system-owned directory, you may need to sign in
  12. as the administrator or "root" account. If you do not have administrative
  13. access to this machine, you may wish to choose a different installation
  14. directory, preferably one that is listed in your PYTHONPATH environment
  15. variable.
  16. For information on other options, you may wish to consult the
  17. documentation at:
  18. https://setuptools.readthedocs.io/en/latest/easy_install.html
  19. Please make the appropriate changes for your system and try again.

mac&linux

报错日志也可以看到,是由于权限问题,那么(mac或linux上)只需要加上sudo提权即可

  1. sudo python setup.py install

执行就能正常执行install命令

  1. running install
  2. running bdist_egg
  3. running egg_info
  4. creating Hello.egg-info
  5. writing Hello.egg-info/PKG-INFO
  6. writing top-level names to Hello.egg-info/top_level.txt
  7. writing dependency_links to Hello.egg-info/dependency_links.txt
  8. writing manifest file 'Hello.egg-info/SOURCES.txt'
  9. reading manifest file 'Hello.egg-info/SOURCES.txt'
  10. writing manifest file 'Hello.egg-info/SOURCES.txt'
  11. installing library code to build/bdist.macosx-10.15-x86_64/egg
  12. running install_lib
  13. running build_py
  14. creating build/bdist.macosx-10.15-x86_64
  15. creating build/bdist.macosx-10.15-x86_64/egg
  16. copying build/lib/hello.py -> build/bdist.macosx-10.15-x86_64/egg
  17. byte-compiling build/bdist.macosx-10.15-x86_64/egg/hello.py to hello.pyc
  18. creating build/bdist.macosx-10.15-x86_64/egg/EGG-INFO
  19. copying Hello.egg-info/PKG-INFO -> build/bdist.macosx-10.15-x86_64/egg/EGG-INFO
  20. copying Hello.egg-info/SOURCES.txt -> build/bdist.macosx-10.15-x86_64/egg/EGG-INFO
  21. copying Hello.egg-info/dependency_links.txt -> build/bdist.macosx-10.15-x86_64/egg/EGG-INFO
  22. copying Hello.egg-info/top_level.txt -> build/bdist.macosx-10.15-x86_64/egg/EGG-INFO
  23. zip_safe flag not set; analyzing archive contents...
  24. creating dist
  25. creating 'dist/Hello-1.0-py2.7.egg' and adding 'build/bdist.macosx-10.15-x86_64/egg' to it
  26. removing 'build/bdist.macosx-10.15-x86_64/egg' (and everything under it)
  27. Processing Hello-1.0-py2.7.egg
  28. Copying Hello-1.0-py2.7.egg to /Library/Python/2.7/site-packages
  29. Adding Hello 1.0 to easy-install.pth file

Windows

在windows上,需要使用管理员权限打开cmd窗口,然后执行命令就可以了。

发表评论

表情:
评论列表 (有 0 条评论,111人围观)

还没有评论,来说两句吧...

相关阅读