Trying to download modules but python can't find them - python

So I need some modules for a project and after trying a lot of things and googling a lot of things I still can't get it to work. I used this code to test if the module was working:
import sys
sys.path.append('c:\users\my name\anaconda2\lib\site-packages')
import numpy
x = randn(100,100)
And I got this error:
Traceback (most recent call last):
File "C:\Users\My Name\Desktop\test.py", line 3, in
import numpy
ImportError: No module named numpy
Any idea why I'm doing wrong?

You can try two things:
1) which python
And see what python you are using. You may be still pointing to old python the system has. In that case add ~/anaconda2/bin to $PATH environment variable.
2) sys.path.append('c:\users\my_name\anaconda2\lib\python2.x\site-packages')
Usually anaconda library is installed under lib\pythonx.x(the correct python version number)\site-packages. So change that.
If none of the above worked, then just do clean install from scratch all over again.

Related

How to use Python modules for interactive scripting in Valor NPI tool

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.

Separate versions of Python on same computer won't import same modules

I've been coding in Python 3.7.2 as my usual, but an API that I really want for my code only supports up to 3.6 (and does not support 2.7). I downloaded Python 3.6.4 to my computer, which also downloads a separate instance of the IDLE (not a problem). If I try to import something like numpy to my code in 3.7 (ex. import numpy as np) then it works as expected. However, if I do the same in the 3.6 IDLE I get:
Traceback (most recent call last):
File "", line 1, in
import numpy as np
ModuleNotFoundError: No module named 'numpy'
I think that it's a path problem but I'm unsure on how to fix it, and I can't find a solution to this problem elsewhere. Any help is appreciated, thanks.
Step 1: Get the location of the python executable from IDLE
import sys
print(sys.executable) # e.g. /Users/jk/.../bin/python
Step 2: Run the pip in the same folder as the one returned above.
/Users/jk/.../bin/pip install numpy
P.S. It's better to maintain libraries independently for each distribution, or even better use virtualenv or conda to create environments.
Try to install numpy specifically for python3.6:
python3.6 -m pip install numpy

PyCharm does not run – Project Interpreter problems

First of all, I want to note that I've read a lot of links related to my problem.
I have some problems with running the code when I want to import a module.
Here is an example of the code:
import numpy as np
Then PyCharm gives me an exception:
Traceback (most recent call last):
File "/Users/Alexander 1
2/PycharmProjects/Coursera/Week1/Vectors/Vecors.py", line 1, in
import numpy as np
ModuleNotFoundError: No module named 'numpy'
Process finished with exit code 1
I have read this and did all what was written. However, it hasn't been working. I've reloaded the PyCharm – no result.
Help me, please! I'm using MacOS 10.13.5, PyCharm 2018.1.4 CE.
You probably have created a new project using virtualenv, read about it here.
It basically creates a new project specific environment, so the libraries inside won't cause a conflict with python2 and python3 packages. So, inside Pycharm, open terminal by pressing alt+f12 , which will open a terminal inside Pycharm, and install numpy usually by pip install numpy
I don't know why, but when I rebooted the computer and created a new project, this problem has disappeared.

ImportError: No module named operator

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.

Panda 3D Python import error on OSX

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).

Categories

Resources