Skip to main content

Posts

Showing posts with the label Python 3

Python ModuleNotFoundError: No module named 'pyttsx3'

Description: I had already installed Python 3 and after that I have installed Anaconda 3. When installing pyttsx3 using pip install pyttsx3 on CMD I got success message. But when I run IDLE (Python 3) import command it returned error (ModuleNotFoundError: No module named 'pyttsx3'). On investigating I have found out while installing Anaconda I checked 'set python default path' and when using pip on CMD It was installing module on other python instance. Solution: Open Python 3 from the start menu from the installation path (C:\Users\ UserName \AppData\Local\Programs\Python\ Python310 \python.exe). use below commands to install the module. import pip pip.main(['install', 'pyttsx3']) pip.main(['install', 'pypiwin32'])  (Most of the time you need to install pypiwin32 for avoiding the errors likes: No module named win32com.client, No module named win32, or No module named win32api)    That's It, hopefully this post helped and you got the s...

How to set Python Interpreter in Visual Studio Code on Windows

First you need Python Project Virtual Environment Path: Open Command Prompt and navigate to Python Project folder by using below cd C:\Users\Atif\Django\ProjectFolder Now type " pipenv --venv " and press Enter.  CMD will return it's Virtual Environment Path (like:  C:\Users\Atif\.virtualenvs\ProjectFolder-TwJ6wRTs), select and copy you will need this in next section. Add \Scripts\python.exe at the last of the above Path which should be look like below now: C:\Users\Atif\.virtualenvs\ProjectFolder-TwJ6wRTs\Scripts\python.exe Now to main part of this article. Start the " Visual Studio Code " application. Open the Python project. Now from the Menu of "Visual Studio Code" click on " View " and from Sub Menu select " Command Palette.. Ctrl+Shift+P ". A new search bar will be available, type " Python Interpreter " and from below drop down select. A new pick folder path bar will be available here you need to paste the python vir...

How to import .py file in REPL which is placed on different path in Python 3

Follow below steps for importing .py file in REPL (PowerShell, CMD). import sys sys.path.insert(1, 'C:/Users/Atif/PycharmProjects/Import_Txt_URL') import MODULE_NAME as alias if you create empty file with name __ init __.py  Python will consider it as module. Its very existence tells Python to treat the directory as a package. Python checks in the directories in sequential order starting at the first directory in sys.path list, till it find the .py file it was looking for. sys.path Documentation