I installed scikit-learn with pip (pip install -U scikit-learn). I then went to ipython and ran import sklearn, but if I then try to load any modules, they aren't found. In particular, the tab completion of sklearn doesn't seem correct:
In [2]: sklearn.
sklearn.base sklearn.clone sklearn.externals sklearn.re sklearn.setup_module sklearn.sys sklearn.test sklearn.warnings
Any idea what's going on here? Other modules load fine. For example, numpy works normally.
Import the submodule you want to use explicitly:
import sklearn.<submodule>
print sklearn.<submodule>.function()
or
from sklearn.<submodule> import function
print function()
In large python packages, oftentimes the submodules need to be explicitly imported. This is so that the user can pick and choose what to import without importing the entire package (which can negatively affect startup time).
Related
I was trying to run this program below but it's showing the error "No module named 'lab_utils_common'", what can I do to solve this problem?
import numpy as np
import matplotlib.pyplot as plt
from lab_utils_common import plot_data, sigmoid, dcl
plt.style.use('./deeplearning.mplstyle')
lab_utils_common package is either not publicly available or not actively maintained.
Two possible scenarios:
lab_utils_common is a published package, but not installed. Use pip or conda to install.
lab_utils_common is supposed to be a local module written to lab_utils_common.py, but is missing. See more on modules if interested.
I'm using scikit-learn on a supercomputer. I'm using the presently installed versions of the packages I need, and it works just fine. I have a local copy of the code for development.
Due to some apparent discrepancy in the sklearn and numpy versions on the system, I get the following warnings:
python3.7/site-packages/sklearn/utils/__init__.py:4: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Sequence
python3.7/site-packages/sklearn/ensemble/weight_boosting.py:29: DeprecationWarning: numpy.core.umath_tests is an internal NumPy module and should not be imported. It will be removed in a future NumPy release.
from numpy.core.umath_tests import inner1d
I don't need to see this warning or fix anything because I'm not developing anything on this system, I just need it to run. But if I use this code in production mode, I am going to get this warning in my error file millions of times and I won't be able to find any errors that actually matter.
In my python scripts I have:
import warnings
warnings.simplefilter(action='ignore', category=DeprecationWarning)
import numpy as np
from sklearn import ensemble
from sklearn import metrics
in my bash script I have:
jsrun -n $2 python3 -W ignore::DeprecationWarning myscript.py $args &
I've read a lot of the answers to similar questions but I don't see why I'm still getting this warning. How can I make it go away?
Im newbie in python and know i a task from my lecturer to use ANFIS. so I intall anfis in my virtual environent using
pip install anfis
and now I try to import that
import anfis
import membership #import membershipfunction, mfDerivs
import numpy
i got problem
ModuleNotFoundError: No module named 'membership'
so what I must do?
Looks like membership is part of the anfis package, but you are trying to import it as if it were an independent package in itself. Since you haven't installed any package called membership (probably because it doesn't exist as a package), you are getting a ModuleError.
Solution:
First of all, remove the following statement from your code, which is causing the error message:
import membership
Next, since you are already importing the entire anfis package, you can just use a function from the membership module in your code like this:
import anfis
# some code
mfc = membership.membershipfunction.MemFuncs(mf)
Check this link from the anfis GitHub repo for an example on how to use the membership function.
This seems to be a common problem. Try reading through this discussion and see if anything there helps you.
https://github.com/twmeggs/anfis/issues/4
I would like to know if it is possible to parameterized the way a module import one of its own module.
My problem is the following. I have a number of generic tensorflow functions, such as losses, that work with both version (1 and 2) of the API.
If the module is used with TF2, or with an old version of TF1, tensorflow needs to be imported like
import tensorflow as tf
However if I use TF 1.15, or if I want to use the version 1 of the API with TF2, tensorflow needs to be imported as
import tensorflow.compat.v1 as tf
tf.disable_v1_behavior()
So the way the import is done cannot be automatically deduced from the TF version, as TF2 can be used in TF1 "compatibility" mode.
Is there a way I can change the way the import is done in the module?
A hack that seems to work for modules that are directly imported:
import my_module
my_module.tf = tf
That forces the tf module to be the same as the current one. However,
This could have invisible and hard-to-track side effects since tensorflow is imported with potentially different APIs requirement, this could mess up any global variable settings.
This works for modules imported directly, not for modules that are imported by other modules, unless the hack is propagated to all modules.
I use, as in https://stackoverflow.com/a/32965521/2069610:
>>> import pkg_resources
>>> pkg_resources.get_distribution("tensorflow").version
'XX.XX'
Another idea would be to grep:
$ pip freeze | grep tensorflow
tensorflow==XX.XX
are you using pip or conda? This might also offer couple of different options, based on the output of conda list or so..
Based on that, you could use one or the other import...
I have a sconstruct file and i am trying build a process.
A part of my code is below.
# Import modules needed by Scons
import os
import sys
# Create an Scons Environment
env = DefaultEnvironment()
env.Decider('MD5-timestamp')
sys.path.append(r"C:\Python27\Lib\site-packages")
sys.path.append(r"C:\Python27\Lib\site-packages\numpy")
sys.path.append(r"C:\Python27\Lib\site-packages\numpy\linalg")
import numpy
When i try to run scons, it complain about not able to find some sub module of numpy such as lapack_lite, _umath_linalg. The screenshot of the error attached.
I have checked this files inside my site-pacages. It is defintely present inside the folder.
When i import numpy library from python, i dont have any problem.
I had a dependency issue.
The only solution that worked was to completely remove python, all its libraries.
Reinstall python, libraries and scons back. Made sure all pythonpath and sys path are set properly.
It started to work