问题描述
pip 说 minizinc
已经安装,但是当我尝试在代码中调用它时,它给我错误说它没有安装.
(后端) bash-3.2$ pythonPython 3.8.3(默认,2020 年 7 月 2 日,11:26:31)[Clang 10.0.0] :: Anaconda, Inc. on darwin输入帮助"、版权"、信用"或许可证"想要查询更多的信息.>>>从 minizinc 导入实例、模型、求解器/Users/miranda/.local/share/virtualenvs/backend-BjqhdW2P/lib/python3.8/site-packages/minizinc/__init__.py:25: RuntimeWarning: MiniZinc 在系统上找不到.无法初始化默认驱动程序.警告.警告(回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中.导入错误:无法从minizinc"导入名称实例"(/Users/miranda/.local/share/virtualenvs/backend-BjqhdW2P/lib/python3.8/site-packages/minizinc/__init__.py)>>>出口()(后端)bash-3.2$ pip install minizinc已满足要求:/Users/miranda/.local/share/virtualenvs/backend-BjqhdW2P/lib/python3.8/site-packages (0.4.2) 中的 minizinc(后端)bash-3.2$ python3 -m pip install minizinc已满足要求:/Users/miranda/.local/share/virtualenvs/backend-BjqhdW2P/lib/python3.8/site-packages (0.4.2) 中的 minizinc(后端)bash-3.2$ python -m pip install minizinc要求已经满足:minizinc in/Users/miranda/.local/share/virtualenvs/backend-BjqhdW2P/lib/python3.8/site-packages (0.4.2)
如 MiniZinc Python 的 入门" 页面.MiniZinc Python 与 MiniZinc 本身不同,它只是 Python 与 MiniZinc 的连接.
这意味着在您可以使用 MiniZinc Python 之前,您还必须安装 MiniZinc 包.这就是错误试图告诉你的.该捆绑包可在 MiniZinc 网站上找到.
请注意,安装 MiniZinc 后,每当您在 Python 中 import minizinc
时,MiniZinc Python 都会在您的计算机上查找 minizinc
可执行文件.如果您没有在通常的位置安装 MiniZinc,那么您可能需要将 PATH
环境变量附加到 minizinc
所在的目录以使其工作.>
pip says minizinc
is already installed, but when I try to call it in code, it gives me error saying it is not installed.
(backend) bash-3.2$ python
Python 3.8.3 (default, Jul 2 2020, 11:26:31)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from minizinc import Instance, Model, Solver
/Users/miranda/.local/share/virtualenvs/backend-BjqhdW2P/lib/python3.8/site-packages/minizinc/__init__.py:25: RuntimeWarning: MiniZinc was not found on the system. No default driver could be initialised.
warnings.warn(
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Instance' from 'minizinc' (/Users/miranda/.local/share/virtualenvs/backend-BjqhdW2P/lib/python3.8/site-packages/minizinc/__init__.py)
>>> exit()
(backend) bash-3.2$ pip install minizinc
Requirement already satisfied: minizinc in /Users/miranda/.local/share/virtualenvs/backend-BjqhdW2P/lib/python3.8/site-packages (0.4.2)
(backend) bash-3.2$ python3 -m pip install minizinc
Requirement already satisfied: minizinc in /Users/miranda/.local/share/virtualenvs/backend-BjqhdW2P/lib/python3.8/site-packages (0.4.2)
(backend) bash-3.2$ python -m pip install minizinc
Requirement already satisfied: minizinc in /Users/miranda/.local/share/virtualenvs/backend-BjqhdW2P/lib/python3.8/site-packages (0.4.2)
As explained on MiniZinc Python's "Getting Started" page. MiniZinc Python is not the same as MiniZinc itself, it is merely a connection from Python to MiniZinc.
That means that before you can use MiniZinc Python, you also have to install the MiniZinc bundle. This is what the error is trying to tell you. The bundle can be found on the MiniZinc website.
Note that after the installation MiniZinc Python will look on your computer for the minizinc
executable whenever you import minizinc
in Python. If you haven't installed MiniZinc in the usual location, then you might need to append your PATH
environment variable with the directory in which the minizinc
to make it work.
这篇关于安装了 minizinc 但 python 认为没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!