AttributeError: module 'lightgbm' has no attribute 'LGBMClassifier' - lightgbm

I installed lightgbm with conda install -c creditx lightgbm=0.2.0,and import lightgbm success, but when I import LGBMClassifier or using LGBMClassifier it fails.
Error is:
<module 'posixpath' from '/usr/anaconda3/lib/python3.5/posixpath.py'>
Traceback (most recent call last):
File "/root/Final_Contest/ligGBM.py", line 12, in <module>
gbm = lgb.LGBMClassifier(objective='binary',num_leaves=31,learning_rate=0.1,n_estimators=3000)
AttributeError: module 'lightgbm' has no attribute 'LGBMClassifier'
What could be the case?

I removed the graphviz and lightgbm package from Anaconda Prompt and installed the libraries using conda install.
It worked for me.

Related

Problem installing importlib on Mac with pip3

Good morning!
Until yesterday I was using python 2.7 and using the following code for writing output files for my scripts:
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
But now I'm upgrading my code to python 3.7, so now I need to use importlib.reloadinstead of just reload. However, typing sudo -H pip3 install importlib on my shell gives me the following error:
Collecting importlib
Using cached https://files.pythonhosted.org/packages/31/77/3781f65cafe55480b56914def99022a5d2965a4bb269655c89ef2f1de3cd/importlib-1.0.4.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 6, in <module>
import distutils.core
File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/core.py", line 16, in <module>
from distutils.dist import Distribution
File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 19, in <module>
from distutils.util import check_environ, strtobool, rfc822_escape
File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/util.py", line 9, in <module>
import importlib.util
ModuleNotFoundError: No module named 'importlib.util'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-3cz_3d6n/importlib/
After looking for solutions I also tried to upgrade setuptools, but that didn't fix my problem.
Many thanks in advance!
importlib at PyPI is an outdated package intended for very old Python versions. For new versions of Python importlib is a module from the standard library, you don't need to install it, it's always available.

ImportError with python-pptx

I faced with problem when I installed python-pptx with conda on cleaned environment:
conda install -c conda-forge python-pptx. After install was successfully finished I tried to import pptx module and got following error:
>>> import pptx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\SazonovEO\AppData\Local\Continuum\anaconda3\envs\new\lib\site-p
ackages\pptx\__init__.py", line 13, in <module>
from pptx.api import Presentation # noqa
File "C:\Users\SazonovEO\AppData\Local\Continuum\anaconda3\envs\new\lib\site-p
ackages\pptx\api.py", line 17, in <module>
from .package import Package
File "C:\Users\SazonovEO\AppData\Local\Continuum\anaconda3\envs\new\lib\site-p
ackages\pptx\package.py", line 13, in <module>
from .opc.package import OpcPackage
File "C:\Users\SazonovEO\AppData\Local\Continuum\anaconda3\envs\new\lib\site-p
ackages\pptx\opc\package.py", line 13, in <module>
from .oxml import CT_Relationships, serialize_part_xml
File "C:\Users\SazonovEO\AppData\Local\Continuum\anaconda3\envs\new\lib\site-p
ackages\pptx\opc\oxml.py", line 12, in <module>
from lxml import etree
ImportError: DLL load failed: Не найден указанный модуль.
But if I installed this library (python-pptx) with pip like this (also into new cleaned environment):
pip install python-pptx
this works.
I have following versions: python version - 3.7.1, python-pptx-0.6.17, lxml-4.3.0.
Do you have any ideas about this issue?
Reinstallation lxml from pkgs/main channel from anaconda repo allow workaround issue:
conda install lxml
The following packages will be UPDATED:
libxml2 conda-forge::libxml2-2.9.8-h9ce36c8_1~ -->
pkgs/main::libxm l2-2.9.9-h464c3ec_0 libxslt
conda-forge::libxslt-1.1.32-heafd4d3_~ --> pkgs/main::libxs
lt-1.1.33-h579f668_0
The following packages will be SUPERSEDED by a higher-priority
channel: ... lxml
conda-forge::lxml-4.3.2-py37heafd4d3_0 --> pkgs/main::lxml-
4.3.2-py37h1350720_0 ...
First of all, try the following command in your terminal in order to enable the conda-forge:
conda config --add channels conda-forge
Secondly, run the following command and after a while enter [y]:
conda install python-pptx

Cannot install enum package on Python3.6

I am trying to run this example on MacOS High Sierra. It requires installing the page package, which requires installing the pytodos package, which requires installing the enum package, installation of which fails.
$ python3 page_object_test_case.py
Traceback (most recent call last):
File "page_object_test_case.py", line 3, in <module>
import page
ModuleNotFoundError: No module named 'page'
$ pip3 install page
...
Successfully installed click-6.7 page-1.0.16
$ python3 page_object_test_case.py
Traceback (most recent call last):
File "page_object_test_case.py", line 3, in <module>
import page
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/page/__init__.py", line 2, in <module>
from pytodos import todo
ModuleNotFoundError: No module named 'pytodos'
$ pip3 install pytodos
Collecting pytodos
...
Collecting enum==0.4.6 (from pytodos)
Downloading https://files.pythonhosted.org/packages/0c/4e/1ea357e7783c756bb579333c1e4a026fb331371ee771f616ffedc781e531/enum-0.4.6.tar.gz
Complete output from command python setup.py egg_info:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/version.py:1: UserWarning: Module enum was already imported from /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/enum.py, but /private/var/folders/h3/1znktv0s36j1fdqcdrr0zvcw0000gn/T/pip-install-jhfn7vc3/enum is being added to sys.path
import pkg_resources
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/h3/1znktv0s36j1fdqcdrr0zvcw0000gn/T/pip-install-jhfn7vc3/enum/setup.py", line 24, in <module>
version = main_module.__version__
AttributeError: module 'enum' has no attribute '__version__'
Note that I've tried to do the same on Ubuntu. And I had to repeat every step. However, installation of enum failed with this error instead:
AttributeError: module 'enum' has no attribute 'IntFlag'
What am I doing wrong?
You went wrong at pip install page.
You were supposed to provide your own module page.py, as described here.
pip install page pulled in some garbage and unrelated/unmaintained projects from PyPI.

Version upgrade to scikit-learn

I wanted to do LDA on some data and so followed this example:
http://scikit-learn.org/stable/auto_examples/decomposition/plot_pca_vs_lda.html#example-decomposition-plot-pca-vs-lda-py
however, on trying:
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
I got an import error. Huh, maybe this is a new function, I thought. So I updated scikit-learn via conda from 0.15.2 to 0.17. But now I can't even import sklearn:
import sklearn
RuntimeError: module compiled against API version a but this version of numpy is 9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "//anaconda/lib/python2.7/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone
File "//anaconda/lib/python2.7/site-packages/sklearn/base.py", line 9, in <module>
from scipy import sparse
File "//anaconda/lib/python2.7/site-packages/scipy/sparse/__init__.py", line 213, in <module>
from .csr import *
File "//anaconda/lib/python2.7/site-packages/scipy/sparse/csr.py", line 13, in <module>
from ._sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
ImportError: numpy.core.multiarray failed to import
I tried updating numpy and scipy using both pip and conda to no avail. I then tried a complete clean re-install of anaconda by:
rm -rf ~/anaconda
and a subsequent download of the .pkg from http://docs.continuum.io/anaconda/install#anaconda-install
Still I get the same error. Here are my OS and package details:
Mac OSX 10.5.2
bash-3.2$ conda -V
conda 3.18.6
scipy==0.16.0
numpy==1.9.1
scikit-learn==0.17
The last of these via pip freeze since I can't import it. I'm going nuts here. Any help much appreciated.
Try:
conda install numpy=1.10.1
I've had that module compiled against API version a but this version of numpy is 9 error before, and this solved it for me.

issue with python 3.4+ and pip

I installed pip 3.4 recently , however i cant seem to use pip properly ( which is included with the latest python 3) it gives me this error whenever i attempt to import it :
"Traceback (most recent call last)
File "<pyshell#8>", line 1, in <module>
import pip
File "C:\Python34\lib\site-packages\pip\__ini... line 9, in <module>
from pip.log import logger
File "C:\Python34\lib\site-packages\pip\log.p... line 8, in <module>
from pip import backwardcompat
File "C:\Python34\lib\site-packages\pip\backw... line 27, in <module>
console_encoding = sys.__stdout__.encoding
AttributeError: 'NoneType' object has no attribute 'encoding"``
If you are using python under WIN OS, pip works as a WIN command: try to directly type "pip install .package." in your cmd shell.

Resources