I am tying to modify the original sklearn.CalibrationCV to create my won version. The original code has "from .utils.fixes import signature". So I did the following in my version:
from sklearn.utils.fixes import signature
but got a error:
ImportError: cannot import name signature
When check the sklearn source code on GitHub. I see the following code inside fixes.py:
try:
from inspect import signature
except ImportError:
from ..externals.funcsigs import signature
Then I did from inspect import signature directly. Still get "ImportError: cannot import name signature"
Besides how to fix this, I am also curious about why the original version can import a module that will be imported from another source? Thanks.
In python 2, the inspect module does not have a signature method.
In python 3, the inspect module does have a signature method.
This code is just trying to work with both python 2 and 3.
You may want to use the funcsigs module if you are using python 2, or use sklearn.externals.funcsigs directly (for version sklearn >= 0.17).
The accepted answer doesn't work with the latest version of sklearn.
Please install funcsigs directly using
pip install funcsigs
and use from funcsigs import signature instead.
Related
I would like to use the mdss_bias_scan function of aif360 for detecting the combination of variables that make up the privileged group and the non-privileged group.
When I try to import the function:
from aif360.sklearn.metrics import mdss_bias_scan
I get the following error:
Import error: cannot import 'mdss_bias_scan' from 'aif360.sklearn.metrics'.
Can you help me to fix it?
Update
The function mdss_bias_scan is not available in the version of aif360 you're using (v0.4.0).
Here's the source code of the file metrics.py at tag v0.4.0.
The function mdss_bias_scan was added via this commit which has not yet been released.
From the GitHub Source, it seems that you should import it as:
from aif360.sklearn.metrics.metrics import mdss_bias_scan
Also, make sure you have aif360 package installed in your Python environment. If not, install it using:
pip install aif360
I am trying to import ArrayLike doing from numpy.typing import ArrayLike, and I get the error mentioned in the title:
ModuleNotFoundError: No module named 'numpy.typing'
I know I could simply write import numpy.typing as npt as the documentation shows, but I would like the simplicity of just importing the types that I want to use. It is also not the first time that this has happened to me: I want to import a specific method/class but I'm forced to import the parent module with a nickname instead because otherwise, I get an Error. Why's that?
Re-posting the resolution in the comments above as a community wiki for better visibility:
The numpy typing module was introduced in numpy 1.20
Make sure that you have the correct numpy version by running the following at the beginning of your notebook:
%pip install -U numpy
In my case, my version of numpy was correct but I could not get rid of the error:
AttributeError: module 'numpy' has no attribute 'typing'
What helped was to directly import the module at the top of the file:
import numpy.typing
Then I was able to use either numpy.typing.ArrayLike or np.typing.ArrayLike.
I'm having a challenging time getting the Python azure-cosmos library to correctly load for the purposes of locally testing a function in VS Code.
The specific error I'm getting (with the file path shortened) is: Exception: ImportError: cannot import name 'exceptions' from 'azure.cosmos' ([shortened]/.venv/lib/python3.8/site-packages/azure/cosmos/__init__.py)
Things I've checked/tried so far:
Check that requirements.txt specifies azure-cosmos
Manually go into python for each of the interpreters available within VS code and ensure I can manually import azure.cosmos
As instructed here, attempt to reinstall the azure-cosmos library using pip3 and ensuring the --pre flag is used.
[Updated] Verified I can successfully import azure.cosmos.cosmos_client as cosmos_client without any errors
Any ideas? Thanks! Below is the relevant section of my code.
import datetime
import logging
import tempfile
import requests
import os
import zipfile
import pandas as pd
import azure.functions as func
from azure.cosmos import exceptions, CosmosClient, PartitionKey
def main(mytimer: func.TimerRequest, calendars: func.Out[func.Document]) -> None:
logging.info("Timer function has initiated.")
This is what you face now:
This is the offcial doc:
https://github.com/Azure-Samples/azure-cosmos-db-python-getting-started
This doc tells you how to solve this problem.
So the solution is to install pre version.(George Chen's solution is right.)
Didn't install the pre version is the root reason, but please notice that, you need to first delete the package. Otherwise, the pre version will not be installed.(Only run install pre will not solve this problem, you need to delete all of the related packages first. And then install the pre package.)
Whether azure.cosmos is needed depends on whether function binding meets your needs, if the binding could do what you want suppose you don't need to use azure.cosmos.
About this import error, I could reproduce this exception, and I check the github solution it have to add a --pre flag.
So my solution is go to task.json under .vscde, add the flag to the command like below.
If you want to get more details about cosmos binding you could refer to this doc:Azure Cosmos DB trigger and bindings
I'm calling yahoo_fin.options.get_expiration_dates() from a very simple code, such that it's unlikely that I have loaded other modules with the same name.
My whole code is this:
import matplotlib.pyplot as plt
import pandas as pd
from numpy import *
from yahoo_fin import options
plt.style.use("seaborn")
expirationDates = options.get_expiration_dates("goog")
The output of the last line is:
NameError: name 'HTMLSession' is not defined
Can you help me understand what's going on?
yahoo_fin requires requests-html for a few of its functions, including the yahoo_fin.options.get_expiration_dates method. You can install it using pip (it requires Python 3.6+):
pip install requests-html
Once installed, you need to restart your Python session. This link provides information on what functionality requires requests-html.
From azure.mgmt.network.operations import NetworkSecurityGroupsOperations
ImportError: No module named operations
Error in importing submodule operations from this package
Version of the package is: azure-Mgmt-network==2.0.0 rc2
You can use code like below to import NetworkSecurityGroupsOperations:
from azure.mgmt.network.v2017_09_01.operations.network_security_groups_operations import NetworkSecurityGroupsOperations
You can get more details with this link and you can change the v2017_09_01 with which version you need.