正如标题中清楚描述的那样,尽管我已经通过the suggested way成功地安装了PyMongo(执行命令python -m pip install pymongo
),但是当我尝试执行以下脚本时却遇到了类似ImportError: No module named 'pymongo'
的错误:导入PyMongo
。
Python
版本:3.7.0
PyMongo
版本:3.7.1
(表示最匹配)
p.s。 (1)操作系统是Windows 10。
(2)类似问题的答案无效。
编辑:这是命令python -m easy_install pymongo
的输出:
Searching for pymongo
Best match: pymongo 3.7.1
Processing pymongo-3.7.1-py3.7-win-amd64.egg
pymongo 3.7.1 is already the active version in easy-install.pth
Using c:\users\talha\appdata\local\programs\python\python37\lib\site-packages\pymongo-3.7.1-py3.7-win-amd64.egg
Processing dependencies for pymongo
Finished processing dependencies for pymongo
命令python -m pip install pymongo
的输出:
Requirement already satisfied: pymongo in c:\users\talha\appdata\local\programs\python\python37\lib\site-packages\pymongo-3.7.1-py3.7-win-amd64.egg (3.7.1)
我执行的命令通过我的Python脚本模拟Android设备,该脚本同时使用MonkeyRunner
和PyMongo
模块:
monkeyrunner.bat C:\Users\talha\Documents\PyCharmProjects\MonkeyRunner\test.py
而且,这是完整的错误堆栈跟踪:
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an exception
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call last):
File "C:\Users\talha\Documents\PyCharmProjects\MonkeyRunner\test.py", line 3, in <module>
from pymongo import MongoClient
ImportError: No module named pymongo
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.Py.ImportError(Py.java:304)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.imp.import_first(imp.java:755)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.imp.import_module_level(imp.java:837)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.imp.importName(imp.java:917)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyObject.__call__(PyObject.java:357)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.__builtin__.__import__(__builtin__.java:1173)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.imp.importFromAs(imp.java:1011)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.imp.importFrom(imp.java:987)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.pycode._pyx0.f$0(C:\Users\talha\Documents\PyCharmProjects\MonkeyRunner\test.py:39)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.pycode._pyx0.call_function(C:\Users\talha\Documents\PyCharmProjects\MonkeyRunner\test.py)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyTableCode.call(PyTableCode.java:165)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyCode.call(PyCode.java:18)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.Py.runCode(Py.java:1275)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.__builtin__.execfile_flags(__builtin__.java:522)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:225)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:77)
180904 04:34:13.771:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:189)
答案 0 :(得分:1)
pip
和easy_install
一起安装的东西可能会出现在不同的地方,具体取决于一些事情。
以下是一些疑难解答的想法...
添加
import sys ; print(sys.path)
您的脚本中的某处将显示(长)python搜索路径的列表。 pymongo在其中一个目录中吗?
如果知道它的安装位置,则可以应用以下 hack 使其起作用:
PYTHONPATH=/path/to/parent/dir python myscript.py
(在Windows中设置环境变量是不同的。可能需要进行调整。)
使用virtualenv是您可以采取的一次性步骤,至少可以将所有问题放在同一位置。安装并设置好之后,安装的所有内容都将放在您的virtualenv中。能够轻松切换环境也很好。
答案 1 :(得分:0)
您缺少一个要点:public static function archives(int $id)
{
return User::find($id)->menus()
->selectRaw('week(date, 1) as kw, year(date) as year')
->orderByRaw('min(date) asc')
->groupBy('kw', 'year')
->get();
}
是另一个基于jython的python解释器,因此,无论您安装了多少其他python解释器以及使用monkeyrunner
或它们一起安装了哪些软件包,都没有关系easy_install
。
如果您想要类似于pip
的基于python的解决方案,请选中AndroidViewClient/culebra。