importing qmc as submodule in scipy - python

When I write from scipy.stats import qmc I face Import Error in Jupyter notebook:
ImportError: cannot import name 'qmc' from 'scipy.stats' (C:\winapps\Anaconda3\lib\site-packages\scipy\stats\__init__.py)
I want to do Halton sampling, how can I solve this problem?

The qmc module was added in version 1.7.0 of scipy (around July 2021). You probably need to update the package. Since you are using Anaconda, you can use:
conda install scipy=1.7
Although this might break you base environment. Instead, you would better off creating a new environment using conda:
conda create -n myenv scipy=1.7 pandas ipykernel

Related

Unable to import patch sklearn

after importing and installing required packages and libraries I am encountering an import error on patch_sklearn().
from sklearnx import patch_sklearn()
patch_sklearn()
ImportError: cannot import name 'sparse_lsqr' from 'sklearn.utils.fixes' (C:\Users\yogis\AppData\Roaming\Python\Python38\site-packages\sklearn\utils\fixes.py)
Didn't know what you want to do here.
But you can try this:
from sklearn.feature_extraction.image import extract_patches_2d
You must install scikit learn version 1.0 and not 1.1
pip install scikit-learn==1.0
Then after this, restart kernel. If it doesn't work after this, I also had to force reinstall the other packages for conda.
conda install numpy scipy joblib scikit-learn --force-reinstall
and then restart kernel. It worked fine. This is a known bug and is fixed on pypi releases but not yet on conda.

Networkx & Jupyter Notebook using pip AttributeError

Hi everyone, I'm trying to create a network visualization with python using the networkx package. Unfortunately I'm getting a "AttributeError: module 'scipy.sparse' has no attribute 'coo_array'" at the end of my code. I've tried to fix it but every help in the internet points towards upgrading pip or conda which I've done and still get the same error. I'm using jupyter notebooks - any help would be greatly appreciated!
#Prerequisites
import sys
!{sys.executable} -m pip install --user networkx
!{sys.executable} -m pip install --user numpy
!{sys.executable} -m pip install --user pandas
pip install notebook --upgrade
conda upgrade notebook
import networkx as nx
import numpy as np
import pandas as pd
from pathlib import Path
from pandas import DataFrame
#Read in Source File - NB this must match the schema requirements
df_InputData = pd.read_excel("/Users/paulkruse/Desktop/FR/Fr1.xlsx")
Src_Column = 'Source ID'
Tgt_Column = 'Target ID'
print(df_InputData);
#Nodes are positioned using the Fruchterman-Reingold force-directed algorithm.
Q = nx.Graph()
arr_SrcTgt= np.array(df_InputData[[Src_Column, Tgt_Column]])
print(arr_SrcTgt);
Q.add_edges_from(arr_SrcTgt)
dict_Coords = nx.spring_layout(Q)
It seems that your scipy version is out of date. The most recent version 1.8.1 certainly has coo_array function. One way to resolve this should be to upgrade scipy. If you're doing this from inside jupyter notebook, then use
!pip install --user scipy==1.8.1
Make sure to restart kernel after installation.

Jupyter lab: module not found though package already installed

This is the complaint that I got:
~\Documents\IT\2020 SUM\32933\Resemblyzer\resemblyzer\audio.py in <module>
4 from typing import Optional, Union
5 import numpy as np
----> 6 import webrtcvad
7 import librosa
8 import struct
ModuleNotFoundError: No module named 'webrtcvad'
After checking solutions, I tried sys.executable and sys.path
then here are the outputs:
C:\Anaconda\python.exe
['C:\\Users\\Jocelyn Huang\\Documents\\IT\\2020 SUM\\32933\\Resemblyzer', 'C:\\Anaconda\\python37.zip', 'C:\\Anaconda\\DLLs', 'C:\\Anaconda\\lib', 'C:\\Anaconda', '', 'C:\\Anaconda\\lib\\site-packages', 'C:\\Anaconda\\lib\\site-packages\\win32', 'C:\\Anaconda\\lib\\site-packages\\win32\\lib', 'C:\\Anaconda\\lib\\site-packages\\Pythonwin', 'C:\\Anaconda\\lib\\site-packages\\IPython\\extensions', 'C:\\Users\\Jocelyn Huang\\.ipython']
Then I check the root package, It has "webrtcvad":
I also tried the conda env, though the package is also available, I still received the same complaint in this env:
After many attempts, I still cannot figure out what it going on here,
excuse my poor knowledge about this...
Follow the below steps:
Uninstall webrtcvad
pip uninstall webrtcvad conda uninstall webrtcvad
Take restart of your system
Install webrtcvad again
conda install webrtcvad
Also to check package installed with conda you need to do conda list instead of pip list
I don't really have the answer as to why this happens, but recently it happened with me and steps shared above resolved it.

ModuleNotFoundError: No module named 'numpy' - Jupyter Notebook

I'm facing weird issue in my Jupyter-notebook.
In my first cell:
import sys
!{sys.executable} -m pip install numpy
!{sys.executable} -m pip install Pillow
In the second cell:
import numpy as np
from PIL import Image
But it says : ModuleNotFoundError: No module named 'numpy'
I have used this command to install Jupyter notebook :
sudo apt install python3-notebook jupyter jupyter-core python-ipykernel
Additional information :
pip --version
pip 20.2.2 from /home/maifee/.local/lib/python3.7/site-packages/pip (python 3.7)
python --version
Python 3.7.5
Thanks to #suuuehgi.
When Jupyter Notebook isn't opened as root:
import sys
!{sys.executable} -m pip install --user numpy
I've had occasional weird install issues with Jupyter Notebooks as well when I'm running a particular virtual environment. Generally, installing with pip directly in the notebook in this form:
!pip install numpy
fixes it. Let me know how it goes.
Restarting the kernal from the Jupyter Notebook solved this issue for me
I had a similar issue. Turns out I renamed an upstream path. And I hadn't deactivated my conda env first. When I deactivated the env.
conda deactivate
Then when I activated it again, everything was as it should have been.
conda activate sample
Now I am seeing other issues with jupyter themes... but its not impacting my numpy code. So, at least I fixed the "ModuleNotFoundError: No module named 'numpy'" error
I have the same problem. My numpy is installed, I am using the same folder as usual.
If I try 'conda deactivate', I get the message:
ValueError: The python kernel does not appear to be a conda environment. Please use %pip install instead.
I added a print of the 'pip install numpy' result and the 'Module not found error' after
Here is a solution which worked for me:
lib_path="c:\\users\\user\\python_39\\lib\\site-packages\\"
MODULE_NAME = "module_to_import"
MODULE_PATH = lib_path+MODULE_NAME+"\\__init__.py"
import importlib
import sys
spec = importlib.util.spec_from_file_location(MODULE_NAME, MODULE_PATH)
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
import module_to_import

ImportError: No module named pandas. Pandas installed

I am pretty new to programming and am having issues importing pandas to my program. Hoping someone could point me in the right direction to fix this. I am running OSX
regresson.py
import pandas as pd
import Quandl
df = Quandl.get('WIKI/GOOGL')
print df.head
and am getting the error:
import pandas as pd
ImportError: No module named panda
I have anaconda on my system.
Pandas 0.17.1
Numpy 1.11.1
Scipy 0.18.0
Pytz 2016.6.1
make sure to activate your conda environment
in your terminal-
conda create -n environment_name quandl pandas
cd path_to_env
activate environment_name
(environment_name)conda list (make sure u have the right packages)
(environment_name) your_program.py
# if using pip
pip install pandas
# if using anaconda
conda install pandas
#after this step use
condo update -all
Python imports, and the language itself, is case sensitive. This means that after you fix the pandas installation, you'll also need
import quandl
and not
import Quandl
On another note, it's worth noting that we usually call df.head(), not df.head. This way, when working on a Jupyter notebook, as an example, the formatting is nicer. Also you can specify the number of first rows you want to see, such as df.head(10).

Categories

Resources