简体   繁体   English

从另一个Python脚本运行setup.py,路径问题,在调用脚本目录中安装?

[英]Run a setup.py from another Python script, path issue, installing in calling script dir?

First, I've found how to call a script from within an other script in Python, the call works perfectly well, but here's the problem I'm running into : 首先,我发现了如何从Python中的其他脚本中调用脚本,该调用工作得很好,但是这是我遇到的问题:

In order to easy-install my web-app (Bottle) on an another server, I packed inside a /redist rep, with mod_wsgi and PyMySQL source files. 为了在另一台服务器上轻松安装我的Web应用程序(瓶),我在一个/ redist rep中打包了mod_wsgi和PyMySQL源文件。 What I'm trying to achieve is a kind of "setup.py" file, that will launch the /mod_wsgi/setup.py install file and the same with the PyMySQL setup file. 我想要实现的是一种“ setup.py”文件,它将启动/mod_wsgi/setup.py安装文件,并与PyMySQL安装文件相同。

Here's what I'm doing for PyMySQL for example : 例如,这是我为PyMySQL做的事情:

subprocess.call("python3 ./redist/PyMySQL/setup.py install", shell=True)

The instalation runs fine, BUT, I end up with a /build , a /dist and a /PyMySQL.egg-info folders in my app directory, and when I'm trying to launch anything that imports PyMySQL, it told me that the module didn't exist. 安装运行正常,但是,我最终在我的应用目录中包含一个/build/dist和一个/PyMySQL.egg-info文件夹,当我尝试启动导入PyMySQL的任何内容时,它告诉我模块不存在。

If I manually install it (using my terminal I mean, like cd /redist/PyMySQL/ and then py3 setup.py install ), it works great, and the import will then work ... 如果我手动安装它(使用终端,我的意思是,例如cd /redist/PyMySQL/ ,然后是py3 setup.py install ),它会很好用,然后导入就可以了...

Any idea ? 任何想法 ? Am I doing something wrong ? 难道我做错了什么 ?

By advance, thanks :) 提前,谢谢:)

I think this would solve your issue : Python specify popen working directory via argument 我认为这将解决您的问题: Python通过参数指定popen工作目录

I suppose in the "./redist/PyMySQL/" directory could be used as parameter because it is where the setup.py is located 我想在“ ./redist/PyMySQL/”目录中可以将其用作参数,因为它是setup.py所在的位置

try this : 尝试这个 :

subprocess.Popen("py3 setup.py", cwd='/redist/PyMySQL/')

on my end this works : 就我而言,这是可行的:

subprocess.Popen(['py3','setup.py'], cwd='path-of-my-setup')

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

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