I do not know what happened, but suddenly I can no longer run Python code like before. I am on windows and I have a feeling the problem is the result of PATH, because I have seen this error before.
Python gives me the following error when trying to import matplotlib:
ImportError: cannot import name 'axes' from 'matplotlib'
(C:\Users\JohnDoe\AppData\Local\Packages
\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\
Python310\site-packages\matplotlib\__init__.py)
When trying to install matplotlib, I get the following error:
ERROR: Could not install packages due to an OSError: [WinError 5]
Toegang geweigerd: 'C:\\Users\\JohnDoe\\AppData\\Local\\Packages
\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages
\\Python310\\site-packages\\matplotlib\\ft2font.cp310-win_amd64.pyd'
Check the permissions.
My setup:
Windows 11
VS Code installed through the MS Store
Python installed through VS Code, which also installs python through the MS Store
I managed to solve this issue. For future reference, the solution was:
Run pip list, take note of every package starting with ~ and where the first letter is missing (example ~atplotlib instead of matplotlib). The location of the directory is also shown.
Open the location as indicated by pip list in a file explorer, find the package starting with a ~ and delete the folder.
The command pip install matplotlib and pip install --user matplotlib still create a OSerror stating the permission is denied. This error occurs both in the terminal of VS Code, command prompt and command prompt opened as administrator.
The solution to the OSerror is to run VS Code as administrator and then run pip install matplotlib from the terminal in VS Code.
To summarize: delete the conflicting package and reinstall through the VS Code terminal while running VS Code as administrator.
All other suggestions I found online to solve this issue failed for me. These suggestions included changing the permission in windows to full access.
Related
I am trying to learn Python and debug code for the first time in VS Code (latest edition). I have anaconda running and the code I have runs fine by itself but now I need to know how to update the code and debug it for the first time.
I keep getting the following error related to NumPy:
Exception has occurred: ImportError
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
The Python version is: Python3.7 from "C:\Miniconda2\envs\myproject_flask\python.exe"
The NumPy version is: "1.18.5"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed: The specified module could not be found.
In the Miniconda path above the Python.exe is version 3.7.7. I tried to install NumPy like so in myproject directory:
(myproject_flask) c:\MyProject\source\MyProject.Flask>conda install numpy=1.18.5
I still get the same error when I go to F5 to debug and run to a breakpoint.
Need help with my environment.
I need to use VS Code in my Windows environment with Anaconda.
You should launch VS Code from Anaconda Navigator so that the environment is initialized.
When you have problems with importing the numpy C-extensions in Anaconda it's very likely that your virtual environment hasn't been activated. Having just Python on the path is not good enough. You also need access to the libraries. This is what the activation does.
When you are running/debugging code you should see a terminal open. You can tell from the prompt
(myproject_flask) C:\MyProject
that conda has been activated. Sometimes this just takes a bit too long for VSCode. So simply push the start button a second time.
Note that the Code Runner extension in VSCode is also known to cause this kind of problems.
However, I wonder why you are using Miniconda2 with Python3, although in general this should work.
I was getting the error even after adding all the anaconda paths, it was due to VScode running the code in the python debugger terminal which is not able to enter the conda environment.
This worked for me:
press ctrl+Shift+P > Type Terminal:Select Default profile > Select Command prompt
after this code ran in Command prompt by default, inside the environment.
I am a bit lost. I've just recently started working with python and have been able to use other libraries, that I've imported without any issues.
Install via pip command
Restart Visual Studio Community 2019
I can use the library
Now I wanted to import the docx2pdf library. But using the same 3 steps is not working and I don't know what to do.
from docx2pdf import convert <-- gets the error "unresolved import"
Also:
after installing it via pip I get the following message in addition to the installation being a success:
WARNING: The script docx2pdf.exe is installed in 'C:\Users\user\AppData\Roaming\Python\Python37\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
I didn't get this message from other libraries.
I am using windows 10.
Thanks for the help!
In VS Code, when we use the global python environment to install the module, we can use the command "pip show docx2pdf" to check its storage location is: "\users\username\appdata\local\programs\python\python38\lib\ site-packages"
It is recommended that you reinstall the module "docx2pdf" or try to delete the previously installed "docx2pdf" folder and reinstall it.
Run:
On my laptop Windows 10 machine I was able to download the package "xfoil 1.1.1": https://pypi.org/project/xfoil/ in Jupyter Notebook by executing the command "!pip install xfoil". I tried doing the exact same thing on my new desktop and get the error "ERROR: Failed building wheel for xfoil" as well as the warning "UserWarning: Unknown distribution option: 'zip_save'". This is the same error described here: https://www.pythonanywhere.com/forums/topic/27038/ even though I have no issues installing other packages. The conclusion from that thread seemed to be that the package must have an error associated with it, but I am not sure why it would work on one machine but not the other since I am using Anaconda 3.8 for both.
It's a bug in the package: zip_save is misspelled, it must be spelled zip_safe. You cannot do much with it until the author(s) fix the bug.
You can fork the repository, fix the misspelling and install the package from your own repository.
Download the files from here.
On your command line type: python setup.py install
If you get this error:
ValueError: Unknown MS Compiler version 1927
go to
C:\Python39\Lib\distutils
and locate the file: cygwinccompiler.py
In the function
def get_msvcr():
add one more "elif" statement like this one:
elif msc_ver == '1927':
return ["mspdb140.dll"]
I recently installed the opencv package using pip install and I wrote a small code to test it (cvtest.py). The code runs through the python idle shell but running it though the command prompt gives the error
Error while finding module specification for 'cvtest.py' (ModuleNotFoundError: __path__ attribute not found on 'cvtest' while trying to find 'cvtest.py')
I tried uninstalling and reinstalling both python and the package. looking up the system path using python -m site gives these results. I am the only user of my laptop.
sys.path = [
'C:\\Users\\Kareem Mostafa\\Desktop\\Assignments\\computer vision',
'G:\\Python37\\python37.zip',
'G:\\Python37\\DLLs',
'G:\\Python37\\lib',
'G:\\Python37',
'G:\\Python37\\lib\\site-packages',
This is the code I am using
import cv2
x=cv2.imread('backpack for sale.jpg',0)
cv2.imshow('x',x)
update: the problem is happening with all the py files I am having whether they require imports or not. apparently python is looking for _init_.py for all the files as if they are packages. Any idea what is going on?
For anyone else that had this problem (assuming kareemostafa has fixed it now!)
Removing the .py suffix on the python -m command fixes this problem, it appears -m only requires module names whereas running it directly as a python file (no -m option) requires the .py suffix
In your case python -m cvtest should be sufficient.
I received an error on atom, it asked to install ipkernal using pip.
Not sure what to do. I have Anaconda on my system and not pip. Can someone explains whats the error about and how can I solve it in using anaconda.
I was running a python code and saved the file as .py.
import pandas as pd
wd = pd.read_csv("winequality-red", sep = ";")
five = wd.head()
print ("five")
Error message:
No kernel for grammar Python found <br>
Check that the language for this file is set in Atom and that you have a Jupyter kernel installed for it.<br>
To detect your current Python install you will need to run:<br>
python -m pip install ipykernel<br>
python -m ipykernel install --user
This isn't really an answer, but you might have better luck on the dedicated Atom forums.
In your case though, it looks like you haven't installed the proper kernels Hydrogen needs to run Python with. (Of course, I'm just assuming you're using Hydrogen. You haven't actually provided any details about how you are trying to run it).
From the Hydrogen documentation, it takes you to this page for Python kernels.
https://nteract.io/kernels/python
In particular, I think you want to run the command conda install ipykernel