Pycharm win32api module install Error: Non-zero exit code (1) - python

so i got this problem when I try to: import win32api on my Pycharm project.py code. I got this error: Non-zero exit code (1)
I also tried with pypiwin32 and I still got the same error.
What is strange is when I executed the pip install pypiwin32 command on my CMD the instalation of pypiwin32 worked. But it still doesnt work on Pycharm. Thanks for the help

Looks like you're having trouble finding the win32api module.
Don't worry. I will help you solve this issue.
First, if you are using virtualenv, please make sure you have activated your environment.
If you don't know how to activate, please refer these links below:
How to activate virtualenv?
Activate venv (Python 3.7.2) for Windows [duplicate]
Second, when you create the project, please choose New environment using Virtualenv.
Then select Inherit global site-packages and Make available to all projects and press Create button.
This is a screensnap for reference.
Third, you need to edit configuartions.
Like this screensnap shows below, you need to choose .py file by selecting Script Path.
Finally, after everything is configured, it can work well.

Related

in vscode, pygame wont import but it is installed and is working in the windows console ,and the python app thing

im very new to code in general so this could be a stupid beginner problem ive searched for things but i couldnt find something useful for me
under Problems is the message: Import "pygame" could not be resolved
You can use pip show pygame to view the package installed location.
And check whether the installation location is consistent with the version corresponding to the selected Python interpreter.
There are two ways to solve this problem:
"ctrl+shift+P" and change the python interpreter.
If you don't want to change the interpreter, you can use pip -t flodername pygame #flodername is your used python package location. Install the pygame package to the specified directory
First, try restarting your computer or vs code
Use this command in your vs code terminal if the above doesn't work:
pip uninstall pygame
Then reinstall pygame using:
pip install pygame
If this also does not work then follow these steps:
Go to the scripts folder of python.
Open command prompt or Powershell in the script folder.
Use this:
C:\python34\scripts> python -m pip install pygame
Done
As an Anaconda user, I found my packages were being installed to C:\Users\YOUR_USERNAME\anaconda3\Lib\site-packages, which Visual Studio Code was not picking up on.
With the Pylance extension installed, open Settings (File > Preferences > Settings, or Ctrl+,)
At the top, beside Workspace, choose User
Under Extensions > Pylance, scroll until you find Python › Analysis: Extra Paths and select Add item.
Type in the path to which packages are being stored (in this case, C:\Users\YOUR_USERNAME\anaconda3\Lib\site-packages)
Click OK and after a couple moments, you should see something like the below image (i.e, the path is included in the list of paths).
Finally, your Python file should have picked up on the changes, but if not, reload it or VS Code. If nothing else, add another path that packages are being saved to or change your Python Interpreter. Using another virtual environment's interpreter wouldn't be very helpful, after all.
I may be late, but I hope this helped.

Transitioning from CS50 IDE to VS Code (Import module does not work)

I recently finished with PSET9 and wanted to transition from CS50 IDE to VS Code for the Final Project. Problem is I don't know what exactly I need to set up to make it all work. I guessed that I just need to import the CS50 library, which I then did following me checking out their GitHub. I did as instructed pip3 install cs50. However, even though various files were installed, my application.py is still saying that it can't find any modules, see screenshot. Why is that? What do I need to do?
Also what might I still be missing after having resolved this? Do I still need to do something to fully have the CS50 IDE essentially running on the VS Code (server, databases, etc)?
VS Code screenshot
I think you need to create virtual environment for that and then activate it.
Create virtual environment in command line Windows
go to you root app folder.
python3 -m venv env (type this command in terminal)
for activate env type this in windows (env\scripts\activate)
for apple and linux type this in terminal) source env/bin/activate
then use pip install
First thing to do is just make sure you've got those items installed correctly by using these commands in your terminal:
pip show cs50
flask --version
werkzeug --version
If they're installed, but you haven't quit and restarted VS Code, try that.
If you're using a virtual environment, make sure you reactivate it before trying to run your application.
I hope one of these helps solve your problem!

Import "flask" could not be resolved from source Pylance (reportMissingModuleSource)

When I am writing
from flask import Flask
One Yellow line is coming up under flask and stating Import "flask" could not be resolved from source Pylance (reportMissingModuleSource) . Also, I am able to do the work with this package also successfully. But the thing is, I am not able to use autosuggesstions for Classes and methods very well.
Further:
I have checked that flask is installed successfully.
Also I visited this thread https://github.com/microsoft/pylance-release/issues/236
And I set up my settings.json in vscode as follows:
"python.analysis.extraPaths": [
"/media/sarimurrab/New Volume/COURSES/Flask/FlaskMigrateforDatabaseMigrations/2"
]
But Still, unable to resolve the error.
When I did not install the module "flask" in the Python environment currently used in VSCode:
Please use the command "pip --version" to check the source of the module installation tool "pip", the module is installed at this location:
Then, we can use the command "pip show flask" to check the installation location of the module "flask": (It checks whether the installation location of the module is consistent with the Python environment displayed in the lower left corner of VSCode.)
If the "reportMissingModuleSource" message is still displayed here, please reload VS Code.
(F1, Developer: Reload Window)
Are you using a Virtualenv? If so make sure that VSCode is using the virtualenv as your python interpreter, otherwise it will not be able to pick up the packages that you installed inside this virtualenv.
To do so, click on the Python interpreter in your bottom bar, you should get a list of possible python interpreters including your virtualenv.
I had a similar issue while trying to import flask on vscode.
I fixed it by using anaconda. Simply you install the flask module in your created environment example screenshot.
How to create a virtual env in anaconda:
1. On the left sidebar, click on environments.
2. Click create (at the bottom).
3. At the pop-up window, give your vir.env a name
and select the language version.
4. Once created, you can start installing
different modules in your environment.
I hope that helps!
For Linux Mint and for those who have installed flask, but VSCode doesn't find it:
check the Flask path: pip show flask (should be smth like
Location: /home/<username>/.local/lib/python3.8/site-packages
in VSCode click left bottom button and choose the python interpreter, in my case I changed it from python3.9 to python3.8 as we can see it in the flask path.
That's because you have not chosen your path correctly,
type:
pipenv --venv
then it will show you where your virtual env is installed. Check where the packages are installed in your env, and then type what comes to you from the shell\scripts or whatever\python, and the packages will work.
I solved my problem by using a "Global" version of Python. Maybe Pylance had not updated to work with the version of Python I was using.
interpreter language screenshot
I was facing same issue. I tried all solutions from stack-overflow but none worked. But after lot of searching and time waste I found my silly mistake. I had created folder named 'flask' and stored my project there. I'm beginner and going through lot of such silly mistakes. Hope it would help, if somebody commits same mistake.
I think this is a Vscode problem ,just restart the Vscode .
By the following steps, I solved this issue:
1)On the project directory create the .flaskenv file
In the .flaskenv file write the following two lines:
FLASK_ENV=development
FLASK_APP=main.py
Please pay attention that main.py is my main file after writing flask run in the Vscode terminal, additionally, you have to create an env folder or requirement file proviosly.
A few answers (Jill's, Marius's, and Roy's) mention the fact that is necessary to choose the correct Python interpreter to make Pylance function properly. I would like to add the fact that this is still necessary to do when using a Jupyter Notebook with the correct Python kernel already chosen.
It is counterintuitive to choose both Python interpreter and notebook's Python kernel to make things work. It is even more counterintuitive considering the fact that Python interpreter's button (on the left bottom of the screen, on status bar) does not necessarily appear when a Jupyter Notebook is open, but when a Python script is open. For instance, in this screenshot, we see the little line under Scikit-learn's import, indicating a problem with the import (even though the import is successful). However, the correct Python kernel, with Scikit-learn installed, is already chosen. Only opening a Python script we notice that the Python interpreter is the reason of this behavior, because a wrong one is chosen, without Scikit-learn. In some sense, one could think that the reason behind this was a problem with the Python kernel or the Conda environment (it is common to experience this kind of problem when experimenting with Jupyter Notebook and Jupyter Lab). I hope this answer may help those who are searching for solving this problem in the specific context of Jupyter Notebooks inside VS Code. They could ignore the other answers because they could think it is not the case for them.

Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings

I was trying to download a GUI, but the terminal kept giving me this error:
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
I'm trying to install it using this command:
python -m pip install --upgrade pip setuptools virtualenv
Check your Python version and be sure it is installed on your machine
Check the path environment variable
Go to -> "start" and type "Manage App Execution Aliases". Go to it and turn off "Python"
I was having the same issue and I fixed it by using the below method.
Copy two paths of Python
C:\Users\Maninder\AppData\Local\Programs\Python\Python39
C:\Users\Maninder\AppData\Local\Programs\Python\Python39\Scripts
These are the paths where your Python interpreter is installed. Now add this path into your environmental
variable. Put this path into System variable, not in user variable. I was using user variable, so I was facing the issue.
I have a solution for you. Make sure you check the path mark during installation. Then you need to go to Manage App Execution Aliases.
Simply go to your search bar and search for Manage App Execution Aliases. You will find the attached screen and you need to turn off App Installers as you see on the screen. Also, see the path,,, follow Maninder's answer.
Then you are good to go! :)
I had the same issue. In Windows CMD, only: py --version, works.
I tried adding the path on System variables, and it didn't work. If you are using PyCharm as I do, try to run all commands from the IDE's terminal. It usually is on the side bar where the Run and the Console is. If it is not, go to: menu View → Tool Windows → Terminal. It worked just fine for me.
You need to download Python from https://python.org. When in the installation, be sure to check the option that adds Python to PATH.
I haven't gotten this error before and have been using Python a long time, and then suddenly it showed up. I think that it is a result of a Windows update designed to steer you to their store.
In any case: to remedy the problem, go to Settings → app execution aliases → and turn "off" Python. (What they tell you to do, in other words). This should resolve the problem.
If you have installed Python successfully with add python path, ticked on, and have added
C:\Users\<user>\AppData\Local\Programs\Python\Python39
C:\Users\<user>\AppData\Local\Programs\Python\Python39\Scripts
to the path into System variables and have turned off the "aliases" and they all didn't work, you can simply use python instead of python3 in your cmd command.
Check the Aliases for App Execution in Windows. Search for Alias App in your Windows toolbar to find the UI for this. Try turning off anything Python related.
Try adding the following to your "Path" environment variable:
C:\Users\Default\AppData\Local\Programs\Python\Python37
C:\Users\Default\AppData\Local\Programs\Python\Python37\Scripts
Replace Python37 with your own version.
I solved this problem for Visual Studio Code with just writing "python" in the console:
python
After that, Microsoft Store opens automatically with the Python app:
And I just click Get.
And it all work!
All the previous answers are correct, but in my case, I was getting this, because I was not passing the version...
The fix is passing the version:
py.exe -3 your_program
If you're on Windows, you may want to use the Python installer, in Windows Marketplace.
I faced the same error while using Anaconda and trying to link the Python executable path in the command prompt.
It got rectified by going to Settings → App execution aliases → and turning "off" Python. Then again I had to set the path for Python in Anaconda and was successful in executing "python --version" command.
The same thing happened to me even after trying all the above-mentioned steps.
I just restart my system and it was working fine. Do it and if still doesn't fix the issue then make sure you have checked "add python ( any version ) to PATH" before installing Python.
If none of the previous answers are working, you can check if you have the Python executable in your program files.
Go to C:\Program Files and check if you have the Python application. If not, go to the python download website here and download the .exe file.
While installing you must select "Custom install" and select the location as C:/Program Files.
Install it and it should work now from anywhere. This worked for me!
To sincerely resolve this issue, do the following:
Uninstall the Python instance and reinstall it. Note: Make sure you check
"Add variable PATH".
On the command line, type:
python -m pip install --upgrade pip setuptools virtualenv
I got this issue when I used Visual Studio Code as the IDE, and Anaconda as my Python compiler. And you don't need to close the "app alias" in settings, but copy your python.exe to python3.exe in your Anaconda folder.
That happened to me. So, to fix it, you have to follow the following steps:
Uninstall the Python version you already installed.
Go ahead and open the installation file to reinstall it again.
Before hitting Install Now, make sure to tick the box in front of Add Python to path.
Go ahead and complete the installation procedure as usual.
Steps for installing Python
The problem is more subtle than it seems.
For example, if you are using Visual Studio Code on the bottom left, you should see Python X.X.X xx-bit (the X is the version).
If you click in there you will see where the IDE is getting the python.exe from.
Locate that folder into your file explorer and then just follow the answer that is saying to change the environments variables.
So copy the path where python.exe is and add it to the Path variable and do the same where the Script folder is (it is in the same directory where the python.exe is).
Then of course make sure your IDE is using the right Python.
None of the answers here worked for me. I did this and the error went away.
For Windows 11 which I was using, I reran the python-3.10.5-amd64.exe file from my downloads directory and then chose to modify the installation.
Then I followed these easy steps.
Make sure the PIP component is checked before proceeding to install.
Then check 'Add Python to environment variables' if it's not checked already.
Proceed to Install.
At this point, your error will be solved
If you already have the Python executable on your machine and you are getting this error in Windows 10, search for the Python executable and copy its path then copy the path in system variables. It worked for me.
to check in windows
py --version
or restart your pc first then put htis command again
I was also facing this issue after installing python, while running command
python --version in command prompt , error as:
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
So, i too added
the path in environment variable as shown, and it worked:

PYTHON-DOTENV: not working when running from vscode fun button

Hello I have a weird situation where I run my python code from VScode run button, which brings me into Python terminal in VScode, I hvae this error message.
ModuleNotFoundError: No module named 'dotenv'
But if I run the same code in a regular terminal in VScode not Python terminal, I can run the code no error regarding dotenv.
Can you please explain why it is happening?
thank you
Next time, please provide more information, be more clear, and would be better to attach some pictures. Otherwise, it's hard to understand what's your mean, and the people hard to give you suitable suggestions.
I guess the problem you meet just because you run your code with a different environment. The environment which you run across the problem because you haven't installed the 'dotenv' package. It looks like you had installed the package in your global python environment, but you haven't installed the package in your virtual environment. You can add this code in your python file to distinguish which python, which environment you are using:
import sys
print(sys.executable)
If I am right, then you just need to activate your virtual environment(Ctrl+Shift+`), and run the command "pip install dotenv". Before install, you should check which pip you are using, through the command "pip --version". Be sure you had installed the package into your virtual environment.

Categories