[英]Script works in Anaconda Prompt but not via Command Line
I am unable to run a python script in the command line, and this script works great in Jupyter Notebook and via Anaconda Prompt.我无法在命令行中运行 python 脚本,该脚本在 Jupyter Notebook 和通过 Anaconda Prompt 中运行良好。 This appears to be an issue importing the ssl module during initialization of another module I am importing (mygeotab).
这似乎是在我正在导入的另一个模块(mygeotab)的初始化期间导入 ssl 模块的问题。
I have googled the error and done as much as I can to diagnose the most common cause which appears to be PATH issues.我已经用谷歌搜索了这个错误,并尽我所能诊断出最常见的原因,这似乎是 PATH 问题。
I have already diagnosed the PATH to a point, and have added the location of the /lib/ and python.exe to the environment variables.我已经将 PATH 诊断到一个点,并将 /lib/ 和 python.exe 的位置添加到环境变量中。 Also, during testing I began my script with the below to protect myself from path issues and printed the path before and after the 'append', which did not have an impact on the problem.
此外,在测试期间,我使用以下脚本开始我的脚本以保护自己免受路径问题的影响,并在“追加”之前和之后打印了路径,这对问题没有影响。
import sys
print(sys.path)
sys.path.append('C:\\Users\\xxxxxx\\Python Scripts')
sys.path.append('C:\\Anaconda3\\python37.zip')
sys.path.append('C:\\Anaconda3\\DLLs')
sys.path.append('C:\\Anaconda3\\lib')
sys.path.append('C:\\Anaconda3')
sys.path.append('C:\\Anaconda3\\lib\\site-packages')
sys.path.append('C:\\Anaconda3\\lib\\site-packages\\win32')
sys.path.append('C:\\Anaconda3\\lib\\site-packages\\win32\\lib')
sys.path.append('C:\\Anaconda3\\lib\\site-packages\\Pythonwin')
sys.path.append('C:\\Anaconda3\\lib\\site-packages\\IPython\\extensions')
sys.path.append('C:\\Users\\xxxxxx\\.ipython')
sys.path.append('C:\\Anaconda3\\Lib')
sys.path.append('C:\\Anaconda3\\Lib\\site-packages')
print(sys.path)
import mygeotab
import pandas as pd
import pyodbc as py
from mygeotab.ext import feed
import sqlalchemy
from time import sleep
However, when I attempt to run the script via the standard command line, I get the below error:但是,当我尝试通过标准命令行运行脚本时,出现以下错误:
Traceback (most recent call last):
File "PYTHON_GEOTAB_TRIP_FEED.py", line 33, in <module>
import mygeotab
File "C:\Anaconda3\lib\site-packages\mygeotab\__init__.py", line 9, in <module>
from .api import Credentials
File "C:\Anaconda3\lib\site-packages\mygeotab\api.py", line 14, in <module>
import ssl
File "C:\Anaconda3\lib\ssl.py", line 98, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: DLL load failed: The specified module could not be found.
The mygeotab module and ssl.py are both in the locations designated in the Traceback. mygeotab 模块和 ssl.py 都位于 Traceback 中指定的位置。 '_ssl' is the only reference I can not seem to diagnose.
'_ssl' 是我似乎无法诊断的唯一参考。 Again, this works fine in both Notebook and Anaconda Prompt.
同样,这在 Notebook 和 Anaconda Prompt 中都可以正常工作。
Any ideas?有任何想法吗?
This was solved for me by installing a separate instance of Python 3.7, moving the PATH references and other pointers.通过安装 Python 3.7 的单独实例,移动 PATH 引用和其他指针,为我解决了这个问题。 I installed pip, mygeotab, and the other packages into the native Python 3.7 instance.
我将 pip、mygeotab 和其他软件包安装到本机 Python 3.7 实例中。 It just appears you can't use the one baked into anaconda the way I thought.
看起来你不能像我想的那样使用 anaconda 中的那个。 Thanks for the help everyone.
感谢大家的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.