简体   繁体   English

如何在不位于其目录中的情况下运行 setup.py 文件?

[英]How do I run a setup.py file without being in its directory?

To install a package that includes a setup.py file, usually you cd into the root directory where setup.py is located and then run the following:要安装包含 setup.py 文件的包,通常您 cd 到 setup.py 所在的根目录,然后运行以下命令:

python setup.py install

Now my problem is that I'm building an addon for another application, and while I can install "normal" package via code with the following:现在我的问题是我正在为另一个应用程序构建一个插件,虽然我可以通过以下代码安装“普通”包:

subprocess.run([sys.executable, "-m", "pip", "install", package])

I also have to install a couple custom made packages, and if I try to do it like this:我还必须安装几个定制的软件包,如果我尝试这样做:

subprocess.run([sys.executable, "-m", "/MSN-Point-Cloud-Completion-master/emd/setup.py", "install"])

I get the following error: Error while finding module specification for 'MSN-Point-Cloud-Completion-master/emd/setup.py' (ModuleNotFoundError: No module named 'MSN-Point-Cloud-Completion-master/emd/setup')我收到以下错误: Error while finding module specification for 'MSN-Point-Cloud-Completion-master/emd/setup.py' (ModuleNotFoundError: No module named 'MSN-Point-Cloud-Completion-master/emd/setup')

What is annoying me is that if I manually cd into the directory and simply run python setup.py install from the cmd it works just fine.令我烦恼的是,如果我手动 cd 进入目录并简单地从 cmd 运行python setup.py install它工作得很好。

So the problem seems to be passing the relative path to the setup.py file, but as I said, considering this is an addon I need to install that setup.py from code.所以问题似乎是将相对路径传递给setup.py文件,但正如我所说,考虑到这是一个插件,我需要从代码安装该setup.py Any solution?有什么解决办法吗?

Reading comments made me realize a few mistakes.阅读评论让我意识到了一些错误。

First of all I realized that I shouldn't use -m flag in this case and this allow me to execute setup.py correctly.首先,我意识到在这种情况下我不应该使用-m标志,这使我可以正确执行setup.py Also deleted the extra slash in the path and now the following works:还删除了路径中的额外斜杠,现在以下工作:

subprocess.run([sys.executable, "MSN-Point-Cloud-Completion-master/emd/setup.py", "install"])

However, since I wasn't in that directory still, I also got the following error c1xx: fatal error C1083: It is not possible to open file: 'emd_cuda.cu': No such file or directory and the compilation failed.但是,由于我仍然不在该目录中,因此我还收到以下错误c1xx: fatal error C1083: It is not possible to open file: 'emd_cuda.cu': No such file or directory ,编译失败。

This definitely fixed all the problems:这绝对解决了所有问题:

import os
import subprocess

os.chdir("MSN-Point-Cloud-Completion-master/emd/")
subprocess.run([sys.executable, "setup.py", "install"])

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

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