'import' 不是内部或外部命令,也不是可运行的程序或批处理文件

'import' is not recognized as an internal or external command, operable program or batch file

我想使用 Python 在 OracleDb 上工作,因此我安装了 pip install cx_Oracle。在我处理它的整个过程中,一切都很顺利,但过了一段时间我再次想打开 cx_Oracle 它显示了这个错误:

'import' is not recognized as an internal or external command, operable program or batch file.

然后我继续卸载它:

C:\Users\PRATIKBAWANE>pip uninstall cx_Oracle
Found existing installation: cx-Oracle 8.3.0
Uninstalling cx-Oracle-8.3.0:
  Would remove:
    c:\users\pratikbawane\appdata\local\programs\python\python310\cx_oracle-doc\license.txt
    c:\users\pratikbawane\appdata\local\programs\python\python310\cx_oracle-doc\readme.txt
    c:\users\pratikbawane\appdata\local\programs\python\python310\lib\site-packages\cx_oracle-8.3.0.dist-info\*
    c:\users\pratikbawane\appdata\local\programs\python\python310\lib\site-packages\cx_oracle.cp310-win_amd64.pyd
Proceed (Y/n)? y
  Successfully uninstalled cx-Oracle-8.3.0

再次尝试安装它:

C:\Users\PRATIKBAWANE>pip install cx_Oracle
Collecting cx_Oracle
  Using cached cx_Oracle-8.3.0-cp310-cp310-win_amd64.whl (213 kB)
Installing collected packages: cx-Oracle
Successfully installed cx-Oracle-8.3.0
WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
You should consider upgrading via the 'C:\Users\PRATIKBAWANE\AppData\Local\Programs\Python\Python310\python.exe -m pip install --upgrade pip' command.

C:\Users\PRATIKBAWANE>import cx_Oracle
'import' is not recognized as an internal or external command,
operable program or batch file.

那为什么安装成功后还是显示错误:

'import' is not recognized as an internal or external command, operable program or batch file.

我不明白谁能给我解释一下,这样每当它发生时至少我可以有它的原因。 非常感谢!

您 运行 import cx_Oracle 在 Windows 命令行中,而不是在 Python 解释器中。您需要先启动 Python,如下所示:

C:\Users\PRATIKBAWANE>python
Python 3.9.9 (main, Dec 13 2021, 17:45:33) 
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>>

python 在 Windows cmd 中可能有不同的名称,例如 python3py。如果 none 这些工作,您需要检查 Python 是否“添加到 PATH”(google 它)

为什么要在终端中写入?导入不是终端命令,而是 python 一个。您应该首先在您的终端中 运行 python,打开它的解释器并编写 python 代码。或者只是在编辑器中编写 python 代码并在终端中编译它。