I'm rather new to using python and haven't done really anything to configure python. my professor gave us an autograder.py file that checks our python code for correctness. the autograder.py file imports a file called grader.py which then imports something known as cgi (import cgi). inside this cgi file located at '/usr/lib/python2.7/cgi.py' there is a line of code that says
from operator import attrgetter
this is where the problem occurs. i recieve the following error
Traceback (most recent call last):
File "autograder.py", line 12, in <module>
import grading
File "/home/ggkfox/Documents/164-CSCI/1-Assignment/tutorial/grading.py", line 13, in <module>
import cgi
File "/usr/lib/python2.7/cgi.py", line 37, in <module>
from operator import attrgetter
ImportError: No module named operator
it is my understanding that the operator module should be built in (according to other stack overflow posts). this error only occurs when i use python2.7.12 (as opposed to python3.5). i have had a simular issue importing Tkinter in 2.7 aswell.
also i want to say that i have tried uninstalling python using:
sudo apt-get purge python2.7
but it wont even uninstall for me to even attempt to reinstall. im not using any pipenv or desktopenv.
i dont know what else to say, im very new to python coding.
It is almost a necessity to use a virtualenv for each python project.
A virtualenv creates a dedicated python environment and it saves you from a lot of 'operating system' related issues.
Here, you can find some virtualenv solutions compatible with all Python versions, along with the official python 3.6.4 documentation.
Related
When I run some commands, which work, for example neofetch, it gives me a Python error.
username#host:~$ as
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 28, in <module>
from CommandNotFound import CommandNotFound
File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in <module>
from CommandNotFound.db.db import SqliteDatabase
File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
It does that whenever I type an invalid command. This started happening after I installed Python 3.9. I am running Kubuntu with Python 3.10 installed by default.
Modern Linux distributions tend to use a lot of python scripts for internal use; for this reason python gets installed with a plethora of libraries.
The error you are getting is because you replaced that fairly complete system python with a version of your own choosing without providing all the libraries the original came with.
The error you see is emitted by /usr/lib/command-not-found, a script using python3 as found in the system path.
I strongly recommend that you re-install the original python packages and use e.g. anaconda for your specific python needs.
The main takeaway from this is:
DON'T MESS WITH THE SYSTEM PYTHON.
try to find which python are you using using which python and uninstall the first python interpreter it finds.
I am trying to interact with a tool called Valor NPI using a Python script. This tool is used for designing and manufacturing electronic goods. As my first step, I ran a simple "hello world" program and it's running fine. But when I try to run some script using Python modules, it is showing a ModuleNotFound error. To resolve this problem, I've put the required modules and pip manually in that location (\Valor\vNPI_114\edir\all\python). Then, to check if it worked, I wrote a small script using the numpy module and tried to run it in that Valor tool. But it is showing the following error:
File "C:\MentorGraphics\Valor\vNPI_114\edir\all\python\numpy\core\__init__.py", line 22, in <module>
from . import multiarray
File "C:\MentorGraphics\Valor\vNPI_114\edir\all\python\numpy\core\multiarray.py", line 12, in <module>
from . import overrides
File "C:\MentorGraphics\Valor\vNPI_114\edir\all\python\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/MentorGraphics/Valor/vNPI_DIR/sys/scripts/numpy1.py", line 2, in <module>
import numpy as np
File "C:\MentorGraphics\Valor\vNPI_114\edir\all\python\numpy\__init__.py", line 150, in <module>
from . import core
File "C:\MentorGraphics\Valor\vNPI_114\edir\all\python\numpy\core\__init__.py", line 48, in <module>
raise ImportError(msg)
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.8 from "C:\MentorGraphics\Valor\vNPI_114\edir\nv\deps\Python\python.exe"
* The NumPy version is: "1.21.4"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
How can I solve this? How can I use Python modules in that tool?
Python packages are installed in different ways, usually using pip, sometimes using a setup.py, but generally not by just coping a module to your Python directory. In most cases, that won't work.
I have no experience with the Valor NPI tool, and I recommend first searching for documentation of that tool if it supports third-party Python modules. Maybe there is a recommended way of installing.
Otherwise, I think you should install the needed modules using pip for this specific Python installation. In your case, I would execute:
C:\MentorGraphics\Valor\vNPI_114\edir\nv\deps\Python\python.exe -m pip install numpy
And likewise for other packages that you need (replacing numpy by the corresponding module). Since you already copied numpy to your Python directory, you should remove that to avoid conflicts between the different copies.
It looks like it could not find _multiarray_umath.cp310-win_amd64.pyd under your numpy/core folder.
Like #wovano, I suggest you install the module through pip instead of copying the module folder. Sometimes it can work, sometimes will not.
You can follow these steps:
In the terminal create a virtual environment through the command of
python -m venv .venv
use the Python: Select Interpreter command from the Command Palette
(Ctrl+Shift+P) to select the virtual environment .venv
Create a new terminal(Ctrl+Shift+`) that will activate the .venv virtual environment automatically
install the NumPy with the command of pip install numpy
You can refer to this official doc for the detailed steps.
First and foremost, I'm not a very experienced wine user.
Onto the problem. I want to run a Windows executable which in some way or another launches some sort of a python script (presumably, for authorization purposes). In this script, as evident from the error message, an import of "ssl" is present and it fails:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named ssl
I have found that ssl is by default bundled with python 2.6+. I have also found that installing/uninstalling any versions of python inside wine does not fix the issue. Furthermore, I can import ssl inside of wineconsole successfully and also on my linux installation with both python2 and python3.
I don't know how to solve this, but I have a guess that wine pulls python modules from somewhere else, although I haven't been able to find where from exactly and why.
I have been messing around with Python/Panda3D and trying to get my first file to run. I am on OSX and after installing Panda3D I tried to run this file:
import direct.directbase.DirectStart
run()
That was followed by this on the Terminal output:
$ python core.py
Traceback (most recent call last):
File "core.py", line 2, in <module>
import direct.directbase.DirectStart
ImportError: No module named direct.directbase.DirectStart
I have been searching everywhere, but all the forms don't really solve the problem. Any help would be awesome!
Thanks!
This is usually a problem when you're using a version of Python other than the one Panda3D is compiled with. If you are using the 1.9.0 Lion build of Panda3D, make sure you are using the system-provided copy of Python 2.7, by explicitly running "python2.7" or "ppython" (which should be a symlink to the correct version of Python).
I'm trying to fix a little SublimeText2 plugin. the problem seems to be (from SublimeText python console) to be an import error:
Traceback (most recent call last):
File ".\sublime_plugin.py", line 62, in reload_plugin
File ".\rtl.py", line 4, in <module>
from algorithm import get_display
File "lang\algorithm.py", line 20, in <module>
from unicodedata import bidirectional, mirrored
ImportError: No module named unicodedata
since unicodedata is the standard python library, I tried to import it directly in the console and got the same import error. I figured this is because sublimetext isn't using the system installed python version (I'm using python2.7 in a windows machine) but It's own bundled 2.6 python which doesn't bundle the whole standard library.
when I try the import from my usual python interpreter everything works fine.
I tried adding a .pth file that points to "c:\python27\lib" and site-packages etc. which didn't help. adding directly to the path like this:
sys.path.append(c:\\Python27\\lib)
didn't help either. also tried to tweaked my user setting file to include:
{
"PATH": "C:\\Python27;c:\\Python27\\Scripts",
"PYTHONPATH": "C:\\Python27\\Lib;C:\\Python27\\Lib\\site-packages;C:\\Python27\\DLLs"
}
my question divides into two:
how to solve this problem specifically on my dev computer
what is the right way to solve this universally for people trying to install the plugin. making the plugin dynamically aware of the default python installation and adding it to the path.
Also, the strangest thing: The main SublimeText folder in program files actually has the unicodedata.pyd file in it. so I can't figure what the problem is!
Looks like this might be a ST2 bug rather than something you're doing wrong:
http://www.sublimetext.com/forum/viewtopic.php?f=3&t=3462