ImportError for NumPy/SciPy - python

I am trying to run some code that requires importing NumPy and SciPy (I'm using Python 3.4), but I keep getting the following message (my OS is Windows):
import numpy as np # used for linear algebra
ImportError: No module named 'numpy'
I have already downloaded NumPy but I don't know how to set it up correctly. Is there any way to fix this? I've been having this error for a while already.
Update: I found the solution. Apparently I had already downloaded both Anaconda (a distribution of Python) and Python, so I deleted both of them and installed back Anaconda, rebooted the computer and now everything works perfectly (can use NumPy and SciPy).

Related

Python4Delphi can't import numpy

I was curious about Python4Delphi and installed it and looked through the demos a bit. Now I wanted to install Numpy via CMD with pip this went well without errors. but now when I enter the following code in DEMO01 of Python4Delphi I get an error message. If I enter the same code in python it works. How can i solve this?
How i installed Numpy:
pip install numpy
Example code:
import numpy as np
print(np .__version__)
The error i got:
AttributeError: partially initialized module 'numpy' has no attribute '__version__' (most likely due to a circular import). Did you mean: '_version'?
The versions:
Delphi 11,
Python 3.10.4,
Pip 22.1,
Numpy 1.22.4 and
Win64
if i forgot some information let met know.
Can you check you're using the same versions of python using both methods by checking what this returns...
import sys
for p in sys.path:
print(p)
Carefully compare the output of that little bit of code as it'll point out any obvious differences.
From my experiments if you've got more than one Python on your system things can get weird with Python4Delphi so the above should provide evidence if this is your situation.
Importing numpy should actually cause an exception anyway, just not the one you mention in your question. Importing Numpy in demo01 will trigger a div by zero unless you add a MaskFPUExceptions(True); before you execute the python
If you use an embedded Python things will get even worse for you as you'll need to set some additional paths to import anything. The only way I've found to do this properly ATM is by addending paths to sys.path in a small python stub with paths constructed relative to the embedded root (Lib and Lib/site-packages incidentally)

How to import pandas using R studio

So, just to be clear, I'm very new to python coding... so I'm not exactly sure what's going wrong.
Yesterday, whilst following a tutorial on calling python from R, I successfully installed and used several python packages (e.g., NumPy, pandas, matplotlib etc).
But today, when trying to run the exact same code, I'm getting an error when trying to import pandas (NumPy is importing without any errors). The error states:
ModuleNotFoundError: No module named 'pandas'
I'm not sure what's going on!?
I'm using R-Studio (running on a Mac)... here's a code snippet of how I'm doing it:
library(reticulate)
os <- import("os") # Setting directory
os$getcwd()
repl_python() #used to make it interactive
import numpy as np. # Load numpy package
import pandas as pd # Load pandas package
At this point, it's throwing me an error. I've tried googling the answer and searching here, but to no avail.
Any suggestions as to how I'd fix this problem, or what is going on?
Thanks
Possibly your python path for reticulate changed upon reloading Rstudio. Here is how to set the path manually (filepath for Linux or Mac):
library(reticulate)
path_to_python <- "~/anaconda3/bin/python"
use_python(path_to_python)
https://stackoverflow.com/a/45891929/4549682
You can check your Python path with py_config(): https://rstudio.github.io/reticulate/articles/versions.html#configuration-info
I recommend using Anaconda for your Python distribution (you might have to use Anaconda anyway for reticulate, not sure). Download it from here: https://www.anaconda.com/distribution/#download-section
Then you can create the environment for reticulate to use:
conda_create('r-reticulate', packages = "python=3.5")
I use Python 3.5 for some specific packages, but you can change that version or leave it as just 'python' for the latest version.
https://www.rdocumentation.org/packages/reticulate/versions/1.10/topics/conda-tools
Then you want to install the packages you need (if they aren't already) with
conda_install('re-reticulate', packages = 'numpy')
The way I use something like numpy is
np <- import('numpy')
np$arange(10)
You need to set the second argument of the function use_python, so it should be:
For example, use_python("/users/my_user/Anaconda3/python.exe",required = TRUE)
DON'T forget required = TRUE

why doesn't python 3.6.1 recognize numpy or pil or skimage after they have been successfully installed

I am getting these errors trying to run a python3 program in itelliJ IDEA on a mac.
import numpy as np
ModuleNotFoundError: No module named 'numpy'
from PIL import Image, ImageChops
ModuleNotFoundError: No module named 'PIL'
from skimage.feature import match_template # requires numpy, scipy, and six
ModuleNotFoundError: No module named 'skimage'
All of these modules have been successfully installed using pip3. I have confirmed the installs using IDLE. Clearly, it seems, there is more to it than simply installing, but I don't know what it is.
I cannot find anything that addresses concerns on python.org. They, in fact, refer me to Stackoverflow. The closest I found here dealt with numpy and python2.7 on mac. There are no responses to that one.
Look in the Preferences for the Project Interpreter setting, and make sure it's pointing to the right python version.
Secondly, since you're already using and IDE use PyCharm. It's IntelliJ's python specific IDE, and it'll have better documentation on python specific technical problems.

Importing numpy fails

I originally installed the anaconda distribution of python and have been coding primarily in Spyder. Recently I tried to install the Chaco visualization library and had a lot of trouble getting it to work using pip install - so instead I installed the Unthought Tool Suite which comes with Chaco. This means I now have two python distributions, but I'm not using virtualenv.
I get this error when running any code in Spyder using numpy:
ImportError:
dlopen(/Users/snoran/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-
packages/numpy/linalg/lapack_lite.so, 2): Library not loaded:
#rpath/lib/libmkl_intel_lp64.dylib Referenced from:
/Users/snoran/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-
packages/numpy/linalg/lapack_lite.so Reason: image not found
When importing bumpy throguh the IPython console, I get:
ImportError: cannot import name scimath
Does anyone have any suggestions on how to fix this?
I am using Mac OS X

Import error when using scipy.io module

I'm involved in a raspberry pi project and I use python language. I installed scipy, numpy, matplotlib and other libraries correctly. But when I type
from scipy.io import wavfile
it gives error as "ImportError: No module named scipy.io"
I tried to re-install them, but when i type the sudo cord, it says already the new version of scipy is installed. I'm stucked in this point and please help me... Thank you
I would take a guess and say your Python doesnt know where you isntalled scipy.io. add the scipy path to PYTHONPATH.

Categories

Resources