我想在Python CGI脚本中使用安装在// load modules
var request = require('request');
var cheerio = require('cheerio');
//split into array
keywords = ["books", "bags", "shoes"];
// loop task for every keyword
global.i
for (i = 0; i < keywords.length; i++) {
console.log(keywords[i] + " was loaded.");
// get request
request('https://www.amazon.com/s/?url=field-keywords=' + keywords[i], function (error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
// try to use the keyword (doesn't work)
console.log(keywords[i]);
} // end get request
}); // get request end
// Try to use the html outside get request (doesn't work)
console.log(html);
} // loop end
目录中的peewee
库。
当我从控制台运行脚本时,一切正常,但是当我运行CGI脚本时,Python无法找到/home/user/.local/lib/python2.7/site-packages
。之所以会发生这种情况,是因为CGI脚本以不同的用户身份运行,环境不同:peewee
在这种情况下不包含sys.path
。
我尝试在/home/user/.local/lib/python2.7/site-packages
之前手动将/home/user/.local/lib/python2.7/site-packages
添加到sys.path
,但它不起作用。我该怎么做才能让Python找到这个包呢?