"ModuleNotFound: no module named pynput" when running PyCharm project from CMD? [duplicate] - python

This question already has answers here:
Activate venv (Python 3.7.2) for Windows [duplicate]
(2 answers)
Closed 1 year ago.
I installed the pyinput package through the package manager(file>settings>project>project interpreter) in PyCharm and it seems to be working fine from inside the IDE, but when I try to run the program from the CMD, I am getting the
"ModuleNotFoundError: No module named 'pynput'" error.
I tried adding it's parent folder in the path like that
parent_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.path.pardir)
sys.path.append((parent_dir+"/venv/Lib/site_packages").replace("\\", "/"))`
but it doesn't seem to work. What should I be doing in this case?

It looks from your question, as written so far, like you're trying to use a module named pyinput but your code is calling it pynput, which is missing an i. Did you make a typo in your code, or in your question? :)

Related

Why does Python on different computers have different issues with relative imports [duplicate]

This question already has answers here:
Relative imports in Python 3
(31 answers)
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed last month.
I am using python and I created a simple way to write HTML and output the file. I developed this module on 2 computers in which on the main one I could use the following according to the directory tree:
Pypertext:
html.py
widget.py
htmlHeader.py
htmlTitle.py
htmlButton.py
This is the folder of the module that can be imported using:
from pyperclip.htmlHeader import Header
although in htmlHeader.py I have the following import:
from widget import baseWidget
This runs fine on my computer but when I go to the secondary computer I get an error and I fixed by:
from .widget import baseWidget
On my main computer I get an error for the attempted relative import and I feel that in the module script it should not have to be a lot of try except statements to make it work.
I use python 3.10
Python imports depend on a lot of external factors including your current working directory, how you run your programs, sys.path, other libraries that you have installed which might be auto-loaded.
I've had similar problems in the past and thus I've created ultraimport.
It gives the programmer more control over their imports and lets you do file system based imports.
In your htmlHeader.py you could then write:
import ultraimport
baseWidget = ultraimport('__dir__/widget.py', 'baseWidget')
This will always work, on both of your computers, independent of all external factors.

Module not found pycharm [duplicate]

This question already has answers here:
ImportError: No module named 'bottle' in PyCharm
(9 answers)
Closed 5 months ago.
I'm trying to import a function from another python script that is located in the same folder as my current script but it throws ModuleNotFound error.
I checked the path in which Pycharm looks for the module (in this case the spambot.py) and it does look through the current folder for the module so i don't understand why the module isn't found.
This works for me, when I get your problem.
from .spambot import launch_chrome
recap:
i wanted to import a function (named launch) from another script in the same directory (whatsapp folder)
how i solve the problem (though idt its the best solution)
right-click the current directory (whatsapp folder in my case) and create a python package (i name it funcs) in the directory.
in the package, create a init.py file. In the init file, put in the functions that you will import on daily basis.
with the above set up, all u need to do is to go to the script u want to import the function and type this:
from (python package) import (function name)
in my case it would be: from funcs import launch
enter image description here

Pyinstaller cannot import pynput module [duplicate]

This question already has answers here:
Getting error when using pynput with pyinstaller
(2 answers)
Closed 8 months ago.
Hey ive tried coding a script in which i use pynput to detect keybinds being pressed. It works fine itself but sadly once i try to use pyinstaller to make it into an exe file the following error pops up once i try to run it.
I have tried looking up the problem but have not found any working solutions.
I have also read through pyinstaller's documentation but I didn't find anything.
#use this pip install pynput==1.6.8

ImportError: No module named site [PYTHON] -- Error message appeared after working with Python for a while [duplicate]

This question already has answers here:
"ImportError: No module named site" on Windows
(17 answers)
Closed 2 years ago.
Currently when I run a Python code (in Sublime Text 3) or try to run python in the cmd, I always get this:
C:\Users\Leopo\Flask App>python
ImportError: No module named site
In my user variables under the environment variables in PATH it is written: C:\Users\Leopo\AppData\Local\Programs\Python\Python38-32\Scripts\ and C:\Users\Leopo\AppData\Local\Programs\Python\Python38-32\
And in the system variables under PATH it is written:
%PYTHON_HOME%
with PYTHON_HOME : C:\Users\Leopo\App Data\Local\Programms\Python38
I already repaired and reinstalled Python 3.8.3.
Is there maybe a problem regarding the environment settings?
Thanks for the help!
This problem has occurred to almost everyone
In my case, my system needed a restart to fix the problem

How to solve Html module not found error in Python? [duplicate]

This question already has answers here:
How to solve "Unresolved import: HTML" in Python Development?
(2 answers)
Closed 4 years ago.
I am running python 3.7 version and using Pycharm edu. I tried to import the 'html' module. But I am getting the following error,
ImportError: No module named html
Any idea why this happens?
Any idea why this happens?
python throws this error when it can't find tye requested module, make sure that the module correctly installed and you have installed it for python 3.7.

Categories