简体   繁体   English

脚本在 Anaconda 提示但不能通过命令行工作

[英]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?有任何想法吗?

  • Windows Server 2008 R2 Windows 服务器 2008 R2
  • Anaconda 2019.07 x64 Anaconda 2019.07 x64
  • Python 3.7.3 x64 Python 3.7.3 x64

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.

相关问题 从 VBA(或命令行)启动 Anaconda 提示 - Launching Anaconda Prompt from VBA (Or Command Line) 从命令提示符执行 .py 文件引发“ImportError:没有名为 geopandas 的模块”- 脚本在 Spyder 中工作(使用 anaconda) - Executing .py file from Command Prompt raises “ImportError: no module named geopandas”- Script works in Spyder (using anaconda) 程序类被卡住/空闲,并且在Anaconda /命令行提示符中进行第一次调用后不执行其余调用,但在Spyder中有效 - Program class is stuck/idle and does not execute remaining calls after 1st call in Anaconda/Command Line Prompt but works in Spyder 通过命令行在 Ubuntu(或 Linux)上安装 Anaconda - Install Anaconda on Ubuntu (or Linux) via command line 通过PyCharm而不是Anaconda Prompt发出运行python脚本的问题 - Issue running python script via PyCharm but not Anaconda Prompt Python 模块请求在 anaconda 提示符下工作但不在 Windows 10 命令行中工作 - Python module requests working in anaconda prompt but not in windows 10 command line 在 Anaconda 命令提示符中运行 Python 脚本的 Windows 快捷方式 - Windows Shortcut to Run Python Script in Anaconda Command Prompt Python 导入在应用程序中有效,但在命令提示符或脚本中无效 - Python import works in app but not in command prompt or script cx_freeze exe 文件在 anaconda 提示符下工作,但在 windows cmd 命令提示符下不起作用? - cx_freeze exe file works in anaconda prompt but not in windows cmd command prompt? 函数在命令行上起作用,但在脚本中不起作用 - Functions works on command line, but not in script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM