I know this is a problem that's been asked here before, but I have tried all the solutions I found and not solved it. It's possible I'm not understanding the solutions, but I have tried my best.
I am teaching myself Python and it is slow going, so I don't understand a lot yet. I'm using VSCode as an IDE, Python version 3.10, and Windows 10. I only have the Python extension installed for VSCode. My project files are on a flash drive, D. I replaced a couple folder names with [Default Names] in the text below.
I keep trying to debug/run some code in VSCode and the very first line
import numpy as np
gives me the error
Exception has occurred: ModuleNotFoundError - No module named 'numpy'.
But I know that's not true:
`PS D:\0-Career\Programming\PythonCoding\[ProjectFolder]> py -m pip install numpy
Requirement already satisfied: numpy in c:\users\[UserID]\appdata\local\programs\python\python310\lib\site-packages (1.23.1)`
I tried the solution of going to
environment variables > system variables > "Path" > edit > new >
c:\users\[UserID]\appdata\local\programs\python\python310\
as well as
C:\Users\[UserID]\AppData\Local\Programs\Python\Python310\Lib\site-packages\
and
C:\Users\[UserID]\AppData\Local\Programs\Python\Python310\Scripts\
and I also tried adding a user variable called Python. Nothing appears to have changed as a result of these additions.
Some history if it's helpful:
I first started by installing Python using the Microsoft Store. I used IDLE for a bit, and I used my command line to install pip and numpy. They worked for a little while. I later installed Visual Studio Code IDE. I ultimately have uninstalled the Microsoft Store version and installed the application from the Python site for Windows instead. I have also uninstalled and reinstalled it several times trying to fix my issues, and same for numpy. I also searched my C drive for "python" and burned everything from the past couple days and reinstalled and repaired it out of desperation. No luck.
I have tried to the best of my ability to uninstall everything and reinstall everything to start fresh, because numpy worked ever so briefly early on in IDLE, I think until I had installed the web download version of Python. I don't really understand environment variables, so I'm not sure what I'm doing or if I'm doing that wrong, or what needs to be restarted when I try something new, so it's possible I missed something.
Answers a 10 year old could understand would be appreciated! Or terminology I can easily research for an explanation of how to do it.
Ctrl+Shift+P open Command Palette
choose Python:Select Interpreter
Choose the right interpreter
Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
Also Check 64 bit or 32 bit
Download the latest version
and open the location where you downloaded the NumPy module now press the 'SHIFT' key and press right-click on the mouse then a menu will open where you find open PowerShell. open it now PowerShell window opens in the folder now type pip install and the file name and press the TAB button and click enter. then the NumPy module will be installed.
Have Fun
Try adding the variable PYTHONPATH to your system variables and add the following paths to this variable.
C:\PATH_TO_YOUR_PYTHON_INSTALL
C:\PATH_TO_YOUR_PYTHON_INSTALL\DLLs
C:\PATH_TO_YOUR_PYTHON_INSTALL\Lib
C:\PATH_TO_YOUR_PYTHON_INSTALL\Scripts
It should look something like this.
Screenshot of Environment Variables
After you added the variable restart your VS Code and it should work.
I hope this helps.
Related
I started to learn Python and got stuck on my own language (I'm not English Native Speaker), main user folder name was by kirilitsa.
It cause trouble with installing new elements to Python. I changed name and now console don't see Python, I tried to reinstall manual and from Control panel but still it somehow exist in my pc and I can't repair, modify or uninstall it.
I think there is a path which lead to old version of folder name but I can't even imagine where it can be.
Is there any solution or to reinstall windows will be faster?
It shows right way but...:
Changed path:
From the Official Docs.
Do this
Modifying an Existing Installation:
Re-run your installer (e.g. in Downloads, python-3.8.4.exe) and Select "Modify".
Check all the optional features you want (likely no changes), then click [Next]. Check [x] "Add Python to environment variables", and [Install].
UPDATE
NOTE:
I see that from screenshot you are installing the 64-bit Python, what version is your Window?
if is 32-bit then just go here and get the 32 bit (32 bit here)
Run Installer as Amministrator
Have Windows “Run” dialog run as Admin?
How To Run Programs As Administrator In Windows 10
If you still get an error, go manually to your folder, as per screenshot the path should be:
C:\Users\Timur\AppData\Local\Programs\Python\
Follow this instruction
How to add to the PYTHONPATH in Windows, so it finds my modules/packages?
Add
C:\Users\Timur\AppData\Local\Programs\Python\Python39\
And
C:\Users\Timur\AppData\Local\Programs\Python\Python39\Scripts\
5 months later I'm found how to fix the problem.
After several wrong deletion of Python 3.9.1 which screwd up things there still was some in system installer, like this but 3.9.1 version:
You need to kill them all before u could install new version or update. Good proggram which I used: Reg Organizer.
Install it, open important sections registry, find all python 3.9.1 or version you have problem with and delete:
Done! Worked with me.
I too deleted python by mistake and found that I was unable to uninstall or reinstall. When I launched the python installer, the only options I could choose from were - Modify, Repair, Uninstall. Neither modify nor uninstall worked since I got the same message 'No Python 3.9 installation was detected'.
It was perfectly solved using Repair option. I then chose to uninstall completely and reinstall. It would probably also be a good idea to check the environment variable 'Path' and also Registry Editor to make sure there is nothing left over from the previous installation.
I am new to Python so this may be a stupid question, sorry in advance if it is so!
The paths Python searches for modules using Spyder 4.1.4.:
[.., 'D:\Users\Martin\Anaconda3\lib\site-packages', ..]
The paths Python searches for when used via command line in windows:
[.., 'D:\Users\Martin\Anaconda3\lib\site-packages', ..]
Thus, both include path to
'D:\Users\Martin\Anaconda3\lib\site-packages'
where I store my cv2 module installed. Yet, Spyder can import cv2 and to my surprise cmd cannot import cv2 with an error No module named 'cv2'. What am I missing please? Can anyone verify if it works for him in command line please? (I changed/edited the question again to cut unneccessary long talk, though the essence stayed the same, in hope someone could answer).
I solved it. If you have a similar problem, you can check if your case is similar to mine and follow the steps.
I use Spyder and everything works fine. However my goal is to use Python via cmd. This could not be done because Python via cmd could not find my modules.
What I did: After typing python in cmd, Python worked and output its version by default. However, I noticed the version was different than version running in Spyder - I had two Python installations (one of which I didn't know about). I found the installation cmd uses by import sys and print(sys.executable). I uninstalled that Python installation.
Now, typing python in cmd does not do anything, it is an unknown command. Then I followed this guide to add my Python installation to Path (using Windows) by:
My Computer > Properties > Advanced System Settings > Environment Variables >
in System variables, I found "Path", clicked Edit, New, then input my Python installation path D:\Users\Martin\Anaconda3 as well as D:\Users\Martin\Anaconda3\Scripts and D:\Users\Martin\Anaconda3\Library\bin. This solved it for me.
everyone. I installed anaconda to use python and install ai packages. I am new to high-level computer use beyond the normal GUI that windows has blessed us with.
Background: I am just starting using command prompts and am teaching myself python to use for ai with keras and tensorflow. Unfortunately, I cannot get far enough to install these packages because after I install anaconda, I get multiple errors in the command prompt. Access Denied was solved by installing for all users and running as administrator. However, I cannot use conda, and when I use pip, I get constant html errors. Nothing works. I tried adding \Anaconda3 and \Anaconda3\Scripts to PATH, but it doesn't change anything. The prompt starts by telling me that it cannot find the specified paths then kicks me over to C:\Windows\system32, but when I cd back to my \Anaconda3 directory, nothing changes. What am I doing wrong? What do I need to try?
I appreciate it. As basic as this is, rest assured I spent days struggling with this before posting.
I'm using Python 3.5 and I was trying to download and use Pillow 4.0.0. I got it through Conda, and it shows in its package menu, as well as the module list in Pycharm. However, even when I have the project interpreter set to anaconda, it will not recognize Pillow at all. I've also given it some time to scan through everything, to see if that would work.
Invalidating the caches and restarting would work. If you want to refresh the Pycharm cache, try going to the far left of PyCharm, and choose [File|Invalidate Caches/Restart...]
Being a complete begginer in python, I decided to install the python interpreter 3.4.4, and also PyDev plugin for eclipse IDE. I am also using windows 10.
I have encountered a problem regarding certain imports, namely : from PIL import Image, ImageTk, which is apparently an unresolved import.
I have looked at certain questions which were similar to my situation, but most of them gave a solution like installing packaged from the linux apt-get. Here are some topics I visited :
Uninstalling and reinstalling Pillow and pip,
Installing pillow-imaging-tk on Ubuntu,
This topic which left me very confused,
This one seemed helpful, but is on Unix OS again
So please, could someone explain to me why I am seeing this error, and how could I correct it if I absolutely want to use Eclipse, Pydev, windows 10 and Python 3.
Found the solution, here's what I did:
Set the PYTHONPATH like it is shown in this article, make sure python.exe is accessible via cmd,
Via cmd, type pip install pillow. Alternatively, you can enter the same command from Windows+R,
(Not sure if relevant step) Via eclipse, Windows->Preferences->PyDev->PythonInterpreterremove your interpreter to re-add it,
Restart eclipse.
For Python import problems in PyDev, the project web site has a page on interpreter configuration that is a good place to start. I recently had a similar problem that I solved by adding a module to the forced builtins tab.