我们当前项目的很大一部分严重依赖于该集成商。它是用Cython编码的,所以我有一堆同名的文件,例如:“ integrator.pyx”,“ integrator.cpp”和“ integrator.hpp”。还有一个“ setup.py”,用于对“ integrator.pyx”文件进行cythonize。
并且当一切都在Python 2中运行时,一切正常。
但是现在我们试图将其更新为Python 3(如果重要的话,具体为3.4),我们遇到了问题。
我的许多文件都依赖于集成器,因此大多数文件具有:
from integrator import *
这在Python 2中很好用,但是如果我在Python 3中运行相同的文件(我通常在Jupyter笔记本中工作),则会出现错误:
ImportError: no module named 'integrator'
经过大量搜索,我收到了打印出Python 2和Python 3导入路径的建议。我发现目录'/usr/local/lib/python2.7/dist-packages'包含一个名为“ integrator .so”和另一个名为“ integrator-0.0.0.egg-info”的文件,这两个目录都不在“ /usr/local/lib/python3.4/dist-packages”目录中。
当我调用from integrator import *
时,它是调用.so文件,还是引用目录中的.cpp或.hpp文件之一?是否只需将.so文件和/或.egg文件复制到3.4目录帮助中?]
然后我尝试在“导入”命令中添加句点:
from .integrator import *
返回错误:
SystemError: Parent module '' not loaded, cannot perform relative import
[我还试图在Python 3.4中重新编译“ integrator.pyx”文件,以查看是否会创建一个与Python 3兼容的新cythonized代码。尝试时,我得到的只是一个错误:
error: command 'gcc' failed with exit status 1
我已经尝试过查找,但是大多数解决方案要么使我烦恼,要么不起作用,或者由于我正在共享计算机上远程工作,因此我无权进行某些修改。例如,我尝试在.pyx文件中尝试“导入pystan”,但这只会导致[]
[ImportError: no module named 'pystan'
甚至在pip3 install --user pystan
之后
如何在Python 3中实现此功能?
我们当前项目的很大一部分严重依赖于该集成商。它是用Cython编码的,所以我有一堆同名的文件,例如:“ integrator.pyx”,“ integrator.cpp”和“ ...
这是您需要导入的.so文件,这是由Cython setup.py创建的文件。