简体   繁体   English

适当的Unix(.profile,.bash_profile)会改变Python的用法

[英]Proper Unix (.profile, .bash_profile) changes for Python usage

I new to Python and to programming in general. 我是Python新手,也是一般编程人员。 I'm a novice, and do not work in programming, just trying to teach myself how to program as a hobby. 我是一个新手,不参与编程工作,只是想自学如何编程作为一种爱好。 Prior to Python , I worked with Ruby for a bit and I learned that one of the biggest challenges was actually properly setting up my computer. Python之前,我曾与Ruby合作过一段时间,并且我了解到最大的挑战之一是实际上正确设置了我的计算机。

Background: I'm on a Macbook with OSX 10.7. 背景:我使用的是OSX 10.7的Macbook。

With Ruby , you have to (or rather, you should), edit your ./profile and add PATH info. 使用Ruby ,您必须(或者更确切地说,您应该)编辑./profile并添加PATH信息。 When you install and use RVM , there are additional items you need to add to your bash_profile . 安装和使用RVM ,需要向bash_profile添加其他项目。

Do you have to make similar changes with Python ? 您是否必须使用Python进行类似的更改? What are the best practices as I'm installing/getting started to ensure I can install modules and packages correctly? 我正在安装/开始确保可以正确安装模块和软件包的最佳实践是什么?

python works out of the box on OS X (as does ruby , for that matter). python在OS X上开箱即用(就像ruby )。 The only changes I would recommend for a beginner are: 我建议初学者的唯一变化是:

1) Python likes to be reassured that the terminal can handle UTF-8 before it will print Unicode strings. 1)Python喜欢让人放心,终端可以在打印Unicode字符串之前处理UTF-8。 Add export LANG=en_US.UTF-8 to .profile . export LANG=en_US.UTF-8添加到.profile (It may be that the .UTF-8 part is already present by default on Lion - I haven't checked since Snow Leopard.) Of course, this is something that will help you in debugging, but you shouldn't rely on it being set this way on other machines. (可能是.UTF-8部分默认存在于Lion上 - 我从Snow Leopard开始就没有检查过。)当然,这可以帮助你进行调试,但你不应该依赖它在其他机器上以这种方式设置。

2) Install pip by doing easy_install pip (add sudo if necessary). 2)通过easy_install pip安装pip (必要时添加sudo )。 After that, install Python packages using pip install ; 之后,使用pip install安装Python包; this way, you can easily remove them using pip uninstall . 这样,您可以使用pip uninstall轻松删除它们。

Take a loot at Python on the Macintosh page first. 首先在Macintosh页面上获取Python的战利品。 Like it says, Python comes pre-installed on Mac OS X. It means that you don't have to do anything special in order to use it. 就像它说的那样,Python预装在Mac OS X上。这意味着你不必为了使用它而做任何特别的事情。

To get started, you can run a Terminal.app , type python and that will get you Python interactive shell up and running. 首先,您可以运行Terminal.app ,键入python ,这将使您启动并运行Python交互式shell。

However, Python on OS X might be of a slightly older version. 但是,OS X上的Python可能是稍微旧版本。 For example, OS X 10.7.3 comes with Python 2.7.1, whereas latest release version of the Python is 3.2.3. 例如,OS X 10.7.3附带Python 2.7.1,而最新发布的Python版本是3.2.3。 If you want to use other versions, then you will have to install them. 如果要使用其他版本,则必须安装它们。 Then it all depends on what, where and how you install. 那一切都取决于你安装的内容,地点和方式。 If you want to have multiple versions alongside, you may need to set some environment variables like PATH to have binaries you installed found by the bash etc. You can do it through bash ~/.profile if needed. 如果你想有多个版本一起,你可能需要设置一些环境变量,如PATH ,有你安装在由二进制发现bash等,你可以做到这一点通过庆典~/.profile如果需要的话。

But until you get to that point - don't worry about it use a version shipped with OS X. Once you want a newer one - download and install it. 但是直到你达到这一点 - 不要担心它使用OS X附带的版本。一旦你想要一个更新的版本 - 下载并安装它。 Then, if it doesn't work out of the box or you have any other problems or concerns, feel free to ask a more specific question. 然后,如果它没有开箱即用,或者您有任何其他问题或疑虑,请随时提出更具体的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM