在MacOS上安装用户时,我的python软件包路径应该是什么? [英] What should be my python packages path for a user install on MacOS?

查看:81
本文介绍了在MacOS上安装用户时,我的python软件包路径应该是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac OS X上,并且听说为了避免全局安装软件包(使用sudo),这可能会导致OS X使用的python文件出现问题,因此安装python软件包的路径必须与此不同.的OSX.

I'm on Mac OS X and I've heard that to avoid global installation of packages (using sudo) that might cause problems with the python files that OS X uses, the path to install python packages must be different than that of OS X.

当前python可执行文件安装在:

Currently python executables are installed in :

/usr/local/bin/

Pip在此处安装模块:

Pip installs modules over here :

/usr/local/lib/python2.7/site-packages

从这里开始使用Python:

Python is used from here :

/usr/local/bin/python

这些路径安全吗?

推荐答案

如果您使用的是OS X,则还应该在/usr/bin中安装Python:

If you are on OS X, you should also have Python in /usr/bin:

$ which -a python
/usr/local/bin/python
/usr/bin/python

如果使用的是brew,则第一个python应该是符号链接:

If you are using brew, the first python should be a symlink:

$ ls -hl $(which python)
lrwxr-xr-x  1 user  admin    34B Jun 23 16:53 /usr/local/bin/python -> ../Cellar/python/2.7.11/bin/python

如果您不使用brew,则必须向我们解释如何安装python的第二个版本.

If you are not using brew, you will have to explain to us how you installed a second version of python.

您还应该至少有两个site-packages:

$ find /usr -name 'site-packages'
/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
/usr/local/lib/python2.7/site-packages

如果使用brew安装了python,则还应该具有pip:

If you installed python using brew, you should also have pip:

$ which pip
/usr/local/bin/pip

您可能应该将其升级到最新的pip:

You should probably upgrade that to the latest pip:

$ pip install --upgrade pip

使用/usr/local/bin/pip安装python软件包应该是安全的,因为它们将安装在/usr/local/lib/python2.7/site-packages中. /usr/local路径专门用于本地软件.另外,brew会将其文件安装到/usr/local,因此,如果您正在使用brew,则已经在其中安装文件.

It should be safe to install python packages using /usr/local/bin/pip because they will be installed in /usr/local/lib/python2.7/site-packages. The /usr/local path is specifically for local software. Also, brew installs its files to /usr/local, so if you are using brew, you are already installing files there.

我不确定为什么有些人说不全局安装任何软件包.我从未见过任何参考文献可以解释为什么这是一个坏主意.如果多个用户需要同一个软件包,则更明智的做法是在全局进行安装.

I am not sure why some folks say not to install any packages globally. I have never seen a reference that explained why this was a bad idea. If multiple users need the same package, it makes more sense to install it globally.

当我第一次开始使用virtualenv时,它并不总是按我预期的方式工作.我有一台需要多个用户的计算机,该计算机需要requests,并且由于virtualenv的问题,我最终使用pip在全球范围内进行安装.

When I first started using virtualenv, it did not always work the way I expected it to. I had a machine with multiple users that needed requests, and because of problems with virtualenv, I wound up installing it globally using pip.

virtualenvpip自从我第一次开始使用它们以来,已经有了很大的改进,并且我可以看到使用它们如何防止出现一些问题.如果要开发需要软件包最新版本的新软件,则virtualenv允许您安装软件包而不会影响系统的其余部分.但是,我仍然不明白为什么在全球范围内安装软件包不是一个好主意.

Both virtualenv and pip have improved a lot since I first started using them and I can see how using them can prevent some problems. If you are developing new software that needs the latest version of a package, virtualenv allows you to install the package without affecting the rest of the system. However, I still do not see why it is a bad idea to install packages globally.

这篇关于在MacOS上安装用户时,我的python软件包路径应该是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆