在python中安装metaheuristic-algorithms-python库之后,我无法导入它。为什么这样不行?它已安装在我的网站包中,但无法导入。医生说这是只测试Python3。通过查看代码,这看起来应该可以在python2.7中使用。发生什么事?你知道吗
$ virtualenv working
$ . working/bin/activate
$ pip install metaheuristic-algorithms-python
$ ls working/lib/python2.7/site-packages/metaheuristic_algorithms
base_algorithm.py command_line.pyc function_wrappers harmony_search.py simplified_particle_swarm_optimization.pyc version.py
base_algorithm.pyc firefly_algorithm.py genetic_algorithm.py harmony_search.pyc simulated_annealing.py version.pyc
command_line.py firefly_algorithm.pyc genetic_algorithm.pyc simplified_particle_swarm_optimization.py simulated_annealing.pyc
$ working/bin/python -c "import metaheuristic_algorithms"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named metaheuristic_algorithms
你知道他们怎么说不支持Python2吗?好吧,这是在python3上工作而不是在python2上工作的东西之一。具体来说,这个包没有
__init__.py
。你知道吗在python3上,没有
__init__.py
的包是namespace package,这种包的工作方式与常规包略有不同。在python2上,没有__init__.py
的文件夹甚至不是包。您不能导入这个东西,因为Python不认为它是一个包。你知道吗相关问题 更多 >
编程相关推荐