无法在虚拟环境中本地安装PyMySQL [Errno 13]权限被拒绝

问题描述 投票:0回答:1

我正在尝试安全地安装PyMySQL。我已经阅读了许多关于为什么应该避免使用sudo pip install的好论据,但有时似乎无法摆脱它。

有没有办法在OSX中本地安装PyMySQL而不使用sudo

(VirtualEnv) : ^.^ :pip install --no-cache-dir --user PyMySQL
Collecting PyMySQL
  Downloading PyMySQL-0.8.0-py2.py3-none-any.whl (83kB)
    100% |████████████████████████████████| 92kB 1.8MB/s 
Installing collected packages: PyMySQL
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/pip/wheel.py", line 247, in move_wheel_files
    prefix=prefix,
  File "/Library/Python/2.7/site-packages/pip/locations.py", line 153, in distutils_scheme
    i.finalize_options()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/install.py", line 346, in finalize_options
    self.create_home_path()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/install.py", line 565, in create_home_path
    os.makedirs(path, 0700)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Users/TomNason/Library/Python/2.7'
macos permissions pip virtualenv pymysql
1个回答
1
投票

要在虚拟环境中安装,请运行此命令。

pip install --install-option="--prefix=/Users/TomNason/VirtualEnv/lib/python2.7" PyMySQL

一般情况下 - 如果您无法在虚拟环境中使用pip安装PyMySQL(即使您使用的是--user选项),您可以尝试...

pip install --install-option="--prefix=PATH_TO_YOUR_VIRTUAL_ENV_DIR/lib/PYTHON_VERSION" PyMySQL

这对我来说仍然是一个奇怪的情况。欢迎任何关于为什么我必须明确说明我的python目录的评论。我认为使用虚拟环境的原因是pip总是选择安装在那里。

© www.soinside.com 2019 - 2024. All rights reserved.