简体   繁体   English

更改我的Apache本地服务器使用的python安装

[英]Change which python installation my apache local server is using

I have two python installations, one at /usr/bin/env and one through Enthought at /Library/Enthought/User/bin/python. 我有两个python安装程序,一个在/ usr / bin / env上,一个通过在/ Library / Enthought / User / bin / python中的Enthought安装。 The enthought installation has a library that I would like to use in a website that I've inherited from a former coworker. 经过深思熟虑的安装有一个库,我想在我从前同事那里继承的网站中使用该库。

I set up a local server through apache on my Mac OSX 10.10.5 (Yosemite). 我通过Mac OSX 10.10.5(Yosemite)上的apache设置了本地服务器。 I configured httpd.conf and my user configuration file inside of the website folder to execute cgi and py files. 我在网站文件夹中配置了httpd.conf和用户配置文件以执行cgi和py文件。

However, when I try to run my coworker's python scripts through the server, it seems to use the installation without the package I need (/usr/bin/env). 但是,当我尝试通过服务器运行同事的python脚本时,似乎使用的安装没有我需要的软件包(/ usr / bin / env)。 I tried changing the shebang at the top of the script from: 我尝试将脚本顶部的shebang更改为:

'#!/usr/bin/env python' to '#!/Library/Enthought/User/bin/ python' '#!/ usr / bin / env python'到'#!/ Library / Enthought / User / bin / python'

but that gives me an internal service error (500). 但这给了我一个内部服务错误(500)。

One thing I was able to do was to create a symlink using this command: 'sudo ln -s /Library/Enthought/User/bin/python /usr/bin/python' 我能够做的一件事是使用以下命令创建符号链接:'sudo ln -s / Library / Enthought / User / bin / python / usr / bin / python'

Now his script can run and has no trouble finding the right python package. 现在,他的脚本可以运行,并且可以轻松找到合适的python软件包。 However, I'd like to understand why changing the shebang isn't enough. 但是,我想了解为什么更改shebang还是不够的。 Why does the server still access the /usr/bin/env python distribution? 为什么服务器仍然访问/ usr / bin / env python发行版?

A subquestion: Lastly, I created my own test script in the meantime, but I get an Internal Service Error (500) no matter what the shebang is. 一个子问题:最后,在此期间,我创建了自己的测试脚本,但是无论shebang是什么,我都会收到内部服务错误(500)。 This script is in the same folder as his script. 该脚本与他的脚本位于同一文件夹中。 Why can't this script run?: 为什么该脚本无法运行?:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import cgi
import cgitb; cgitb.enable()  # for troubleshooting
print "Content-type: text/html"
print
print "<html><head>"
print ""
print "</head><body>"
print "Hello."
print "</body></html>"

Thanks! 谢谢! I hope this question was clear. 我希望这个问题是明确的。 This is my first experience with web servers, so please correct me if I made any terminology mistakes! 这是我第一次使用Web服务器,因此,如果我在使用术语时出错,请更正我!

The shebang life you quote doesn't work because of the space at the end. 您引用的shebang生活由于末尾的空间而无法使用。 /usr/bin/env is a program, and python is the argument, the name of the program it's supposed to look for. /usr/bin/env是一个程序,而python是参数,它是要查找的程序的名称。 Remove the space from your new shebang and you will be running the Python interpreter directly. 从新的shebang中删除空间,您将直接运行Python解释器。 There's no need to provide it with an argument. 无需为其提供参数。

As to why the other script isn't working, I can only guess that you haven't made it executable, since I can't find any other reason for its failure (but this is a guess). 至于其他脚本为什么不起作用的原因,我只能猜测您没有使其可执行,因为我找不到其他任何导致其失败的原因(但这只是一个猜测)。

Your second print statement does not have an argument. 您的第二个打印语句没有参数。 Try changing it from print to print "\\n" . 尝试将其从print更改为print "\\n"

EDIT 编辑

Try the following script with the appropriate shebang line prepended and, as holdenweb says, make sure it has execute permissions for the right user. 请尝试以下脚本,并在其前面加上适当的shebang行,并按照holdenweb的说明,确保该脚本具有正确用户的执行权限。 Another issue I have run into in the past is with line terminations. 我过去遇到的另一个问题是线路终端。 If you have the "od" utility, run " od -c <filename> " on the command line to do an octal dump for your new file and the existing, working file. 如果您具有“ od”实用程序,请在命令行上运行“ od -c <filename> ”以对新文件和现有的工作文件进行八进制转储。 That way, you can see if the files end with the same line termination("\\r\\n" or "\\n"). 这样,您可以查看文件是否以相同的行终止(“ \\ r \\ n”或“ \\ n”)结尾。

import cgi
print "HTTP/1.0 Status: 200 OK"
print "Content-type: text/html"
print ""
print "<html><head>"
print "</head><body>"
print "Hello."
print "</body></html>"

Note the addition of print "HTTP/1.0 Status: 200 OK" . 注意添加了print "HTTP/1.0 Status: 200 OK" Other than that...I am out of suggestions. 除此之外...我没有建议。

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

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