简体   繁体   English

Python 在 cmd 解释器或 pycharm 中找不到导入

[英]Python can not find imports in either the cmd interpreter or pycharm

The following program generates the following error:以下程序生成以下错误:

import os
#import time
import speech_recognition
from subprocess import call
from platform import python_version
home = os.path.expanduser("~")
from gtts import gTTS
from bs4 import BeautifulSoup
import pyaudio
import PyPDF2
print('Speech Recognition version ' + speech_recognition.__version__)

print('Attempting to read Preamble')
wav = "C:\\Users\\Owner\\PycharmProjects\\Government\\Governing_documents\\Preamble.wav"

recognizer = speech_recognition.Recognizer()
preamble = speech_recognition.AudioFile(wav)
with preamble as source:
    audio = recognizer.record(source)
type(audio)
recognizer.recognize_google(audio)

ERROR MESSAGES FROM PYCHARM:来自 PYCHARM 的错误消息:

C:\Users\Owner\PycharmProjects\Speech\venv\Scripts\python.exe C:\Users\Owner\PycharmProjects\Speech\Wav_to_Text.py 
Traceback (most recent call last):
  File "C:\Users\Owner\PycharmProjects\Speech\Wav_to_Text.py", line 3, in <module>
    import speech_recognition
ModuleNotFoundError: No module named 'speech_recognition'

CMD PROMPT: CMD 提示:

C:\Users\Owner\PycharmProjects\Speech>python Wav_to_Text.py
Traceback (most recent call last):
  File "C:\Users\Owner\PycharmProjects\Speech\Wav_to_Text.py", line 3, in <module>
    import speech_recognition
ModuleNotFoundError: No module named 'speech_recognition'

I tried modifying the environment variables to ensure that the libraries were visible.我尝试修改环境变量以确保库可见。 I checked where the packages were installed and that matched the PATH variable.我检查了软件包的安装位置以及与 PATH 变量匹配的位置。 They still give me an error in PyCharm and cmd他们仍然在 PyCharm 和 cmd 中给我一个错误

 pip install pocketsphinx PyAudio google-api-python-client vosk whisper

Run this command in the terminal and inform us what happened在终端中运行此命令并告知我们发生了什么

this will install all the requierments这将安装所有要求

Just needed to adjust the project files in pycharm. I also had a bad reference to 3.9 when it should have been 3.11.只需要调整 pycharm 中的项目文件。当它应该是 3.11 时,我对 3.9 的引用也很糟糕。 Everything is now working.现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM