Spyder: importerror: cannot import name constants - python

Ubuntu 16.04
Python 2.7
Anaconda 2
I have Anaconda2 installed. This includes the spyder IDE, according to google.
$ spyder
Gives:
Traceback (most recent call last):
File "/home/username/anaconda2/bin/spyder", line 7, in <module>
from spyder.app.start import main
File "/home/username/anaconda2/lib/python2.7/site-packages/spyder/app/start.py", line 13, in <module>
import zmq
File "/usr/lib/python2.7/dist-packages/zmq/__init__.py", line 66, in <module>
from zmq import backend
File "/usr/lib/python2.7/dist-packages/zmq/backend/__init__.py", line 40, in <module>
reraise(*exc_info)
File "/usr/lib/python2.7/dist-packages/zmq/backend/__init__.py", line 27, in <module>
_ns = select_backend(first)
File "/usr/lib/python2.7/dist-packages/zmq/backend/select.py", line 27, in select_backend
mod = __import__(name, fromlist=public_api)
File "/usr/lib/python2.7/dist-packages/zmq/backend/cython/__init__.py", line 6, in <module>
from . import (constants, error, message, context,
ImportError: cannot import name constants
Doesn't work:
$ sudo apt-get purge spyder
$ sudo apt-get install spyder
Doesn't work:
$ conda uninstall spyder
$ conda install spyder
Googling the error doesn't help me along. I'm not a programmer. Python libraries and Anaconda directories and IDE repositories, are all Greek to me. Might be useful information for those who actually know how things work: importing scipy.io also gives me importerrors.
Where is the fault and how do I resolve it?
EDITS
$ conda update chardet
gives:
/home/pieter/anaconda2/lib/python2.7/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.22) or chardet (2.3.0) doesn't match a supported version!
RequestsDependencyWarning)
Solving environment: done
# All requested packages already installed.
and
$ conda update urllib3
gives:
/home/pieter/anaconda2/lib/python2.7/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.22) or chardet (2.3.0) doesn't match a supported version!
RequestsDependencyWarning)
Solving environment: done
# All requested packages already installed.
$ conda info spyder
gives:
absurdly long, long, long list of replies
of which the last is:
spyder 3.2.4 py27h04a3490_0
---------------------------
file name : spyder-3.2.4-py27h04a3490_0.tar.bz2
name : spyder
version : 3.2.4
build string: py27h04a3490_0
build number: 0
channel : https://repo.continuum.io/pkgs/main/linux-64
size : 2.5 MB
arch : None
constrains : ()
license : MIT
md5 : ed9729850ec1ab3c83d87b422e687bc5
platform : None
subdir : linux-64
timestamp : 1508356637551
url : https://repo.continuum.io/pkgs/main/linux-64/spyder-3.2.4-py27h04a3490_0.tar.bz2
dependencies:
chardet >=2.0
jedi >=0.9
nbconvert
numpydoc
pickleshare
psutil
pycodestyle
pyflakes
pygments >=2.0
pylint
pyqt
python >=2.7,<2.8.0a0
pyzmq
qtawesome >=0.4.1
qtconsole >=4.2
qtpy >=1.2.0
rope >=0.9.4
sphinx
myEnv:
(myEnv) pieter#t:~/bagfile_analysis$ spyder
Traceback (most recent call last):
File "/home/pieter/anaconda2/envs/myEnv/bin/spyder", line 4, in <module>
import re
File "/home/pieter/anaconda2/envs/myEnv/lib/python3.6/re.py", line 142, in <module>
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'

Hmmm... have you tried THIS already?
Also, how exactly did you install spyder? Maybe you didn't install it in the right environemnt(in your case probably the default root/base environment)
I'd recommend installing it via conda in the terminal! Also make sure you have installed it in the right environment:
get a list of all your environments:
$ conda env list
install it in a specific environment:
$ conda install --name "your env" spyder
and of course make sure you got the latest anaconda version:
$ conda update -n base conda
EDIT
ok now we know you only have your base environment.
since chardet is a dependency of spyder let's update those two packages first to be sure...
$ conda update chardet
$ conda update urllib3
Let's go on and check your spyder.
Does it work now?
if not try this:
$ conda info spyder
what do you get?
you should get a very long list, but only the last entry is of importance, something like that:
spyder 3.2.5 py27_0
-------------------
file name : spyder-3.2.5-py27_0.tar.bz2
name : spyder
version : 3.2.5
build string: py27_0
build number: 0
channel : https://repo.continuum.io/pkgs/main/osx-64
size : 2.5 MB
arch : None
constrains : ()
license : MIT
md5 : 5ec8ffcda103c23c81005a5aed0c91e7
platform : None
subdir : osx-64
timestamp : 1514270782022
url : https://repo.continuum.io/pkgs/main/osx-64/spyder-3.2.5-py27_0.tar.bz2
dependencies:
chardet >=2.0
cloudpickle
jedi >=0.9
nbconvert
numpydoc
pickleshare
psutil
pycodestyle
pyflakes
pygments >=2.0
pylint
pyqt
python >=2.7,<2.8.0a0
python.app
pyzmq
qtawesome >=0.4.1
qtconsole >=4.2
qtpy >=1.2.0
rope >=0.9.4
sphinx
if you don't get anything back you have installed spyder in the wrong environment and you can skip step 1:
STEP 1:
uninstall spyder again.
$ conda uninstall spyder
STEP 2:
reinstall it
$ conda install spyder
EDIT II
Have you had a look at the link I posted?
the only other thing that comes is in my mind is trying a different environment (for example called "myEnv").
$ conda create --name myEnv spyder
then activate the environment and try to launch spyder. conda tells you how to activate the environment, but i guess it's the same as for mac os:
$ source activate myEnv
$ spyder
$ source deactivate
if that doesn't work you can remove the environment again.
$ conda remove --name myEnv *
In any case the dependency error is weird...

Related

litstudy Package Installation Python

I am Trying to do Co-Citation Network analysis and have to install package called "litstudy" in Python but I am getting an Error installing it in Jupyter and Python 3.10
Link for litstudy package https://nlesc.github.io/litstudy/index.html
In Python 3.10 while installing from Command Prompt getting Error
C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.32.31326\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: legacy-install-failure
It Gets installed in Jupyter but when I import the package I get error
import litstudy
Traceback (most recent call last):
File "C:\Users\vibhu\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\IPython\core\interactiveshell.py", line 3437, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-b5a65b8eaed7>", line 1, in <module>
import litstudy
File "C:\Users\vibhu\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\litstudy\__init__.py", line 1, in <module>
from .sources import * # noqa: F403,F401
File "C:\Users\vibhu\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\litstudy\sources\__init__.py", line 1, in <module>
from .scopus import search_scopus, refine_scopus, fetch_scopus
File "C:\Users\vibhu\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\litstudy\sources\scopus.py", line 236
if doi := id.doi:
If anyone can Solve this for me i will be really grateful I'm stuck on this for amost a day and need to get started with networking analysis or if you have any other solution like this for Citation Networking
TL;DR
Dependencies of the litstudy package are not compatible with Python 3.10, you will have to downgrade to 3.9
Install packages from conda-forge, using conda, so you don't have to compile them.
The long story
The litstudy package has a huge number of dependencies, several of which need to be compiled. The error message you got indicates that compilation failed for some one them.
The dependencies wordcloud and fa2 where a problem on my computer when I ran pip install litstudy to reproduce your problem.
For wordcloud, the exists a pre-compiled Conda bundle for it, available from conda-forge. I recommend using conda (Anaconda3 or Miniconda3, either will do).
This worked for wordcloud, as recommended by its own readme:
conda install -c conda-forge wordcloud
For fa2, there was a second problem: when I ran conda install -c conda-forge fa2, I got this message:
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
- fa2 -> python[version='>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|>=3.8,<3.9.0a0|>=3.9,<3.10.0a0']
Your python: python==3.10.4
which basically says fa2 is not compatible (yet) with Python 3.10. So, you will have to downgrade to a 3.9.x version of Python to use this package.
So to install litstudy and its dependencies, I just created a Python 3.9.12 environment using conda, and then I was able to install everything.
The cut-and-pastable solution
Putting it all together, this worked for me, after installing Miniconda3:
conda create -n py39 python==3.9.12
conda activate py39
conda install -c conda-forge fa2 wordcloud
pip install litstudy
In that environment, import litstudy works fine.

Unable to install PyQt5 with pip

Im running into a problem installing PyQt5 with pip:
pip install pyqt5
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Collecting pyqt5
Using cached PyQt5-5.15.6.tar.gz (3.2 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... error
ERROR: Command errored out with exit status 1:
command: /opt/homebrew/opt/python#3.9/bin/python3.9 /opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py prepare_metadata_for_build_wheel /var/folders/rv/nylh_sjx44b1bq2pmbn1lwkr0000gn/T/tmpi8zk3o59
cwd: /private/var/folders/rv/nylh_sjx44b1bq2pmbn1lwkr0000gn/T/pip-install-9w2kcz7l/pyqt5_a170d636f15d43c8bb4ae5d9a73574fc
Complete output (24 lines):
Querying qmake about your Qt installation...
/opt/homebrew/bin/qmake -query
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 156, in prepare_metadata_for_build_wheel
hook = backend.prepare_metadata_for_build_wheel
AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
main()
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 160, in prepare_metadata_for_build_wheel
whl_basename = backend.build_wheel(metadata_directory, config_settings)
File "/private/var/folders/rv/nylh_sjx44b1bq2pmbn1lwkr0000gn/T/pip-build-env-fyh98wta/overlay/lib/python3.9/site-packages/sipbuild/api.py", line 51, in build_wheel
project = AbstractProject.bootstrap('pep517')
File "/private/var/folders/rv/nylh_sjx44b1bq2pmbn1lwkr0000gn/T/pip-build-env-fyh98wta/overlay/lib/python3.9/site-packages/sipbuild/abstract_project.py", line 83, in bootstrap
project.setup(pyproject, tool, tool_description)
File "/private/var/folders/rv/nylh_sjx44b1bq2pmbn1lwkr0000gn/T/pip-build-env-fyh98wta/overlay/lib/python3.9/site-packages/sipbuild/project.py", line 603, in setup
self.update(tool)
File "project.py", line 160, in update
sipbuild.exceptions.UserException
----------------------------------------
Im using macOS Monterey 12.0.1, with the Apple M1 chip.
What I've tried so far:
Installed PyQt5 using homebrew. Result: PyQt5 got installed via brew but without the necessary package PyQtWebengine. Means when I try to run my application, I receive the error message, that PyQtWebengine package/module is not installed which Im not able to install with pip. So I uninstalled it.
Installed sip and uninstalled
qt (6.2.2) and qt#5 (5.15.2) are installed with brew
Run cmd: python3 -m pip install PyQt5
Pip is up to date (21.3.1)
pip install with a specific PyQt5 Version
Any ideas to solve this problem?
Thanks in advance for any ideas/solutions!
The way I solved the same problem in my M1s was installing the library via terminal launched in Rosetta mode (left click on the Terminal icon -> Get Info -> Open in Rosetta).
So, detailed steps are:
Open a Terminal with Rosetta 2 via left click on the Terminal icon -> Get Info -> Open in Rosetta (https://dev.to/courier/tips-and-tricks-to-setup-your-apple-m1-for-development-547g)
Use non-homebrew python (mine was in /usr/bin/python3) to create virtual environment
$ /usr/bin/python3 -m venv venv
$ source venv/bin/activate
Upgrade pip
(venv)$ pip install --upgrade pip
Install PyQt5
(venv) $pip install PyQt5
Alternatively, you can do a one-off installation via this command:
$ arch -x86_64 python -m pip install PyQt5
I use macos 12.1 (m1), and I use mini-forge with homebrew, I have installed pyqt5 with conda install pyqt.
P.S. my python version is 3.9.
conda create -n py3.9.13 python=3.9.13
conda install pyqt
Worked for me. I'm using macOS Monterey 12.4, with the Apple M1 chip. Anaconda3 installed many dependences automatically while installing. After the above installation, my conda list:
# Name Version
bzip2 1.0.8
ca-certificates 2022.6.15
gettext 0.19.8.1
glib 2.70.2
glib-tools 2.70.2
gst-plugins-base 1.20.3
gstreamer 1.20.3
icu 70.1
jpeg 9e
krb5 1.19.3
libclang 14.0.6
libclang13 14.0.6
libcxx 14.0.6
libedit 3.1.20191231
libffi 3.4.2
libglib 2.70.2
libiconv 1.16
libllvm14 14.0.6
libogg 1.3.4
libopus 1.3.1
libpng 1.6.37
libpq 14.4
libvorbis 1.3.7
libzlib 1.2.12
lz4-c 1.9.3
mysql-common 8.0.29
mysql-libs 8.0.29
ncurses 6.3
nspr 4.32
nss 3.78
openssl 1.1.1p
packaging 21.3
pcre 8.45
pip 22.1.2
ply 3.11
pyparsing 3.0.9
pyqt 5.15.4
pyqt5-sip 12.9.0
python 3.9.13
python_abi 3.9
qt-main 5.15.4
readline 8.1.2
setuptools 62.6.0
sip 6.6.2
sqlite 3.39.0
tk 8.6.12
toml 0.10.2
tzdata 2022a
wheel 0.37.1
xz 5.2.5
zlib 1.2.12
zstd 1.5.2
As I answered here, Rosetta is not required if you're willing to use Homebrew's pyqt#5. Homebrew includes an arm64-compiled pyqt5, and one can leverage its installation in a venv using the --system-site-packages flag to venv:
$ # Install pyqt5 via homebrew
$ brew install pyqt#5
$ # Note that it's installed in python3.9, not 3.10
$ brew cat pyqt#5 | grep 'depends_on.*python'
depends_on "python#3.9"
$ # Make a python3.9 virtualenv with access to the system's site-packages
$ /opt/homebrew/bin/python3.9 -m venv --system-site-packages .venv
$ source .venv/bin/activate

nrfutil - "ImportError: No module named main" on Nixos

I'm using the tool nrfutil which is implemented in Python. To be able to use it under NixOS I was using a default.nix file, that installed nrfutil into a venv. This worked for some time very well. (The last build on the build server using Nix within an alpine container could build the software I'm working on 11 days ago successfully.) When I do exactly the same things (i.e. restarting the CI server build without changes), the build fails now complaining about pip being incorrect:
$ nix-shell
New python executable in /home/matthias/source/tbconnect/bootloader/.venv/bin/python2.7
Not overwriting existing python script /home/matthias/source/tbconnect/bootloader/.venv/bin/python (you must use /home/matthias/source/tbconnect/bootloader/.venv/bin/python2.7)
Installing pip, wheel...
done.
Traceback (most recent call last):
File "/home/matthias/source/tbconnect/bootloader/.venv/bin/pip", line 6, in <module>
from pip._internal.main import main
ImportError: No module named main
To me it seems that the module main should exist:
$ ls -l .venv/lib/python2.7/site-packages/pip/_internal/main.py
-rw-r--r-- 1 matthias matthias 1359 10月 15 12:27 .venv/lib/python2.7/site-packages/pip/_internal/main.py
I'm not very much into the Python environment, so I don't know any further. Has somebody any pointer for me where to continue debugging? How is Python resolving modules? Why doesn't it find the module, that seems to be present to me?
This is my default.nix that I use to install pip:
with import <nixpkgs> {};
with pkgs.python27Packages;
stdenv.mkDerivation {
name = "impurePythonEnv";
buildInputs = [
automake
autoconf
gcc-arm-embedded-7
# these packages are required for virtualenv and pip to work:
#
python27Full
python27Packages.virtualenv
python27Packages.pip
# the following packages are related to the dependencies of your python
# project.
# In this particular example the python modules listed in the
# requirements.txt require the following packages to be installed locally
# in order to compile any binary extensions they may require.
#
taglib
openssl
git
stdenv
zlib ];
src = null;
shellHook = ''
# set SOURCE_DATE_EPOCH so that we can use python wheels
SOURCE_DATE_EPOCH=$(date +%s)
virtualenv --no-setuptools .venv
export PATH=$PWD/.venv/bin:$PATH
#pip install nrfutil
pip help
# the following is required to build micro_ecc_lib_nrf52.a in the SDK
export GNU_INSTALL_ROOT="${gcc-arm-embedded-7}/bin/"
unset CC
'';
}
I replaced pip install nrfutil with pip help to make sure the problem is not the package I try to install itself.
I'm still using python 2.7 as the nrfutil still is not fit for Python 3.
Anyway replacing python27 with python37 did not change the error I get when trying to start pip.)
NixOS version used locally is 19.09. Nix in the CI docker container is nixos/nix:latest which is the nix package manager on Alpine Linux.
Update:
Actually it works when I replace the call to pip install nrfutil with python2.7 -m pip install nrfutil. This actually confuses me even more. python2.7 is exactly the binary that is in the shebang of pip:
[nix-shell:~/source/tbconnect/bootloader]$ type python2.7
python2.7 is /home/matthias/source/tbconnect/bootloader/.venv/bin/python2.7
[nix-shell:~/source/tbconnect/bootloader]$ type pip
pip is /home/matthias/source/tbconnect/bootloader/.venv/bin/pip
[nix-shell:~/source/tbconnect/bootloader]$ head --lines 2 .venv/bin/pip
#!/home/matthias/source/tbconnect/bootloader/.venv/bin/python2.7
# -*- coding: utf-8 -*-
Update 2:
I found out that another way to fix the problem is to edit .venv/bin/pip. This script tried the following import:
from pip._internal.main import main
Which I think is the new module path starting with pip 19.3. But I still have pip 19.2. When I change this line to:
from pip._internal import main
Running pip by typing pip is working.
The thing is I have no idea why the pip script is trying to load the new module path while NixOS still has the old version of pip.
I also opened an issue for NixOS on GitHub: https://github.com/NixOS/nixpkgs/issues/71178
I got your shell derivation to work by dropping the Python27Packages.pip,
(nix-shell) 2d [azul:/tmp/lixo12333] $
>>> pip list
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Package Version
---------------- -------
behave 1.2.6
Click 7.0
crcmod 1.7
ecdsa 0.13.3
enum34 1.1.6
future 0.18.2
intelhex 2.2.1
ipaddress 1.0.23
libusb1 1.7.1
linecache2 1.0.0
nrfutil 5.2.0
parse 1.12.1
parse-type 0.5.2
pc-ble-driver-py 0.11.4
piccata 1.0.1
pip 19.3.1
protobuf 3.10.0
pyserial 3.4
pyspinel 1.0.0a3
PyYAML 4.2b4
setuptools 41.6.0
six 1.12.0
tqdm 4.37.0
traceback2 1.4.0
virtualenv 16.4.3
wheel 0.33.6
wrapt 1.11.2
(nix-shell) 2d [azul:/tmp/lixo12333] $
and my default.nix
with import <nixpkgs> {};
with pkgs.python27Packages;
stdenv.mkDerivation {
name = "impurePythonEnv";
buildInputs = [
automake
autoconf
gcc-arm-embedded-7
# these packages are required for virtualenv and pip to work:
#
python27Full
python27Packages.virtualenv
# the following packages are related to the dependencies of your python
# project.
# In this particular example the python modules listed in the
# requirements.txt require the following packages to be installed locally
# in order to compile any binary extensions they may require.
#
taglib
openssl
git
stdenv
zlib ];
src = null;
shellHook = ''
# set SOURCE_DATE_EPOCH so that we can use python wheels
SOURCE_DATE_EPOCH=$(date +%s)
virtualenv .venv
export PATH=$PWD/.venv/bin:$PATH
pip install nrfutil
#pip help
# the following is required to build micro_ecc_lib_nrf52.a in the SDK
export GNU_INSTALL_ROOT="${gcc-arm-embedded-7}/bin/"
unset CC
'';
}

XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?

I am facing this problem while moving the python-package directory of XGBoost.
Traceback (most recent call last): File "setup.py", line 19, in LIB_PATH = libpath'find_lib_path' File "xgboost/libpath.py", line 46, in find_lib_path 'List of candidates:\n' + ('\n'.join(dll_path))) builtin.XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
Could anyone explain to me how to fix it?
thanks in advance.
You get that message when trying to install the xgboost Python package without the xgboost binaries present. The proper way to install the xgboost Python package from source is the following (assuming you have a compiler such as gcc installed):
git clone --recursive https://github.com/dmlc/xgboost.git
cd xgboost
./build.sh
cd python-package
python setup.py install
I prefer to do it inside a virtual environment. Note that the option --recursive when cloning the repo is essential since it will also clone folders from different repos such as dmlc-core which are necessary for building xgboost.
The other answers didn't work for me so I installed xgboost through Conda commands as listed here.
Just run conda install -c conda-forge xgboost
The first answer's suggestions did not work for me, and left me with the same error as the original question.
If I'm assuming correctly that your full error message is something like this:
C:\Users\Matt\xgboost\python-package>python setup.py install
Traceback (most recent call last):
File "setup.py", line 19, in <module>
LIB_PATH = [os.path.relpath(libfile, CURRENT_DIR) for libfile in libpath['find_lib_path']()]
File "xgboost/libpath.py", line 49, in find_lib_path
'List of candidates:\n' + ('\n'.join(dll_path)))
XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
List of candidates:
C:\Users\Matt\xgboost\python-package\xgboost\xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\../../lib/xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\./lib/xgboost.dll
C:\Users\Matt\AppData\Local\Programs\Python\Python35\xgboost\xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\../../windows/x64/Release/xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\./windows/x64/Release/xgboost.dll
then the solution is to
1) Get/find/download the library that setup.py is looking for. Search the xgboost folder for .dll files. See if you can find something like xgboost.dll it might be called libxgboost.dll. If you can, move to step 2. If you cannot find it download it here
2) Copy the .dll file into the xgboost/python-package/xgboost folder. If that .dll is not called xgboost.dll (i.e. if it's called libxgboost.dll) then change the name to xgboost.dll
3) Run the commands as outlined in Gustavo answer. Note these are meant to be run from Git Bash.
If you want a more soup-to-nuts tutorial, this was the best one I found.
thanks to Joe Nyland that found the a good answer for this problem in here.
As he said (and also worked for me) you need to run following commands:
$ brew install gcc#5
$ pip install xgboost
Try this it worked for me:
brew install gcc-5
brew install cmake
pip install xgboost
In my case (Ubuntu 16.04, with CUDA 9.0) the Python library build was evidently broken by adding R library package to the cmake options list:
1) python lib installation works OK:
cmake .. -DUSE_CUDA=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-${CUDA_VER}
cd /tmp/xgboost/python-package && python3 setup.py install
2) adding '-DR_LIB=ON' switch to cmake breaks subsequent python library installation attempt:
cmake .. -DUSE_CUDA=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-${CUDA_VER} -DR_LIB=ON
cd /tmp/xgboost/python-package && python3 setup.py install
> "XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root
> path?"
I had the same issues. I downloaded the file (xgboost.dll) from
(https://picnet.com.au/blog/xgboost-windows-x64-binaries-for-download/)
into the already existing xgboost folder
(C:\Users\Naganandini\AppData\Roaming\Python\Python37\site-packages\xgboost).
It's perfectly working now :)
I faced the same error while installing xgboost using anaconda prompt because the installation of xgboost was interfering with the versions of some other pre-installed libraries. Installing xgboost by creating a virtual environment solved the issue.
On macOS and Linux:
python3 -m pip install --user virtualenv #Install virtualenv module
python3 -m venv env #Create a virtual environment 'env'
source env/bin/activate #Activate virtual environment
pip install xgboost #Install xgboost
On Windows:
py -m pip install --user virtualenv #Install virtualenv module
py -m venv env #Create a virtual environment 'env'
.\env\Scripts\activate #Activate virtual environment
pip install xgboost #Install xgboost
Refer https://packaging.python.org/guides/installing-using-pip-and-virtual-environments for help regarding virtual environment.
Search for xgboost.dll file under your C:\Users<your-user-name> directory.
If you have installed xgboost, somewhere you should find a copy of the xgboost.dll file.
Once you find the xgboost.dll file, just copy it to one of the paths mentioned in the error message,
e.g. C:\Users<your-user-name>\AppData\Roaming\Python\Python37\site-packages\xgboost\ . Import should work now.
1.I started off with the conda installation from anaconda prompt:
(base) C:\Users\abhi.b>conda install -c anaconda py-xgboost
This lead to the following error :
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: \
Found conflicts! Looking for incompatible packages.
This can take several minutes. Press CTRL-C to abort.|
failed
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
- py-xgboost -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|>=3.5,<3.6.0a0']
Your python: python=3.8
If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.
Decided not to followup this path, as exploring python downgrade was not an option for me.
2.There after i followed "The final attempt that works " on the below link :
https://medium.com/analytics-vidhya/this-is-what-you-should-do-if-you-fail-to-install-the-latest-or-an-older-version-of-xgboost-on-7942a7641eee
However i got the same error as other users faced ::
>>> import xgboost as xgb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\__init__.py", line 11, in <module>
from .core import DMatrix, Booster
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\core.py", line 161, in <module>
_LIB = _load_lib()
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\core.py", line 123, in _load_lib
lib_paths = find_lib_path()
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\libpath.py", line 45, in find_lib_path
raise XGBoostLibraryNotFound(
xgboost.libpath.XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
List of candidates:
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\../../lib/xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\./lib/xgboost.dll
C:\Users\abhi.b\Anaconda3\xgboost\xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\../../windows/x64/Release/xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\./windows/x64/Release/xgboost.dll
>>> exit()
BTW the link to download xgboost.dll as posted above -
https://picnet.com.au/blog/xgboost-windows-x64-binaries-for-download/
was not clear to me ,so i decided to not follow this thread.
3.Finally ,the solution was very simple for me,Open ANACONDA PROMPT and Type
(base) C:\Users\abhi.b>pip install xgboost
This lead to
Collecting xgboost
Downloading xgboost-1.2.1-py3-none-win_amd64.whl (86.5 MB)
|████████████████████████████████| 86.5 MB 1.7 MB/s
Requirement already satisfied: scipy in c:\users\abhi.b\anaconda3\lib\site-packages (from xgboost) (1.5.0)
Requirement already satisfied: numpy in c:\users\abhi.b\anaconda3\lib\site-packages (from xgboost) (1.18.5)
Installing collected packages: xgboost
Successfully installed xgboost-1.2.1
Then goto python prompt
(base) C:\Users\abhi.b>python
>>>import xgboost as xgb
Or you can type the same command on IDE ie Spyder etc
Voila!!

pip not installing numba/llvmlite properly within conda environment

I create a new conda environment
user#machine:~/project$ conda create -n test-env -c numba python=3.5.2 llvmdev=3.8
Fetching package metadata ...........
Solving package specifications: .
Package plan for installation in environment /home/user/anaconda2/envs/test-env:
The following NEW packages will be INSTALLED:
llvmdev: 3.8.1-7 numba
openssl: 1.0.2k-0
pip: 9.0.1-py35_1
python: 3.5.2-0
readline: 6.2-2
setuptools: 27.2.0-py35_0
sqlite: 3.13.0-0
system: 5.8-2 numba
tk: 8.5.18-0
wheel: 0.29.0-py35_0
xz: 5.2.2-1
zlib: 1.2.8-3
Proceed ([y]/n)? y
#
# To activate this environment, use:
# > source activate test-env
#
# To deactivate this environment, use:
# > source deactivate test-env
#
and then activate it and attempt to use specifically pip (not conda) to install llvmlite and numba, which appears to succeed. (Note: I've tried also --no-cache-dir and it doesn't change anything.)
user#machine:~/project$ source activate test-env
(test-env) user#machine:~/project$ pip install llvmlite==0.15 numba==0.30.1
Collecting llvmlite==0.15
Collecting numba==0.30.1
Collecting numpy (from numba==0.30.1)
Using cached numpy-1.12.0-cp35-cp35m-manylinux1_x86_64.whl
Installing collected packages: llvmlite, numpy, numba
Successfully installed llvmlite-0.15.0 numba-0.30.1 numpy-1.12.0
But the library is not installed properly,
(test-env) user#machine:~/project$ python
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:53:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numba
Traceback (most recent call last):
File "/home/user/anaconda2/envs/test-env/lib/python3.5/site-packages/llvmlite/binding/ffi.py", line 42, in <module>
lib = ctypes.CDLL(os.path.join(_lib_dir, _lib_name))
File "/home/user/anaconda2/envs/test-env/lib/python3.5/ctypes/__init__.py", line 347, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /home/user/anaconda2/envs/test-env/lib/python3.5/site-packages/llvmlite/binding/libllvmlite.so: undefined symbol: _ZNKSt14error_category23default_error_conditionEi
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/anaconda2/envs/test-env/lib/python3.5/site-packages/numba/__init__.py", line 9, in <module>
from . import config, errors, runtests, types
File "/home/user/anaconda2/envs/test-env/lib/python3.5/site-packages/numba/config.py", line 11, in <module>
import llvmlite.binding as ll
File "/home/user/anaconda2/envs/test-env/lib/python3.5/site-packages/llvmlite/binding/__init__.py", line 6, in <module>
from .dylib import *
File "/home/user/anaconda2/envs/test-env/lib/python3.5/site-packages/llvmlite/binding/dylib.py", line 4, in <module>
from . import ffi
File "/home/user/anaconda2/envs/test-env/lib/python3.5/site-packages/llvmlite/binding/ffi.py", line 47, in <module>
lib = ctypes.CDLL(_lib_name)
File "/home/user/anaconda2/envs/test-env/lib/python3.5/ctypes/__init__.py", line 347, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libllvmlite.so: cannot open shared object file: No such file or directory
Why does the conda installation of llvmdev from the numba channel fail to "just work".
In my use case, I'm coming to a project that has a pip-styled requirements.txt file, and I need to create conda environments from that file. Some project developers will use venv+pip, some will use conda, and some packages it contains are not found in any anaconda channels, so pip installation is mandatory. We don't want to maintain a separate envrionment.yaml in addition to the requirements.txt, so installing from requirements.txt inside of a conda envrionment is part of my constraints.
Everything seems OK, except for the pip installation of numba/llvmlite, which expects a system dependency of llvm 3.8+. I want to satisfy that as part of the conda environment though.
How can I ensure from a conda environment only that the right llvmdev exists for installing numba and llvmlite?
Installing llvmdev:
Installing llvmdev from the conda-forge channel can be achieved by adding conda-forge to your channels with:
conda config --add channels conda-forge
Once the conda-forge channel has been enabled, llvmdev can be installed with:
conda install llvmdev
It is possible to list all of the versions of llvmdev available on your platform with:
conda search llvmdev --channel conda-forge
HELP:I cloned the relevant files from their GitHub sources and did
python setup.py install
for more without conda use pip
sudo pip install -U llvmlite
sudo pip install -U numba
This is what worked for me using the Anaconda environment:
pip uninstall llvmlite
pip install -U --ignore-installed numba
In an ideal scenario, the required shared library should be present after the installation of llvmlite.
(test-env) ~/condaexpts$ conda create -n test-env -c numba python=3.5.2 llvmdev=3.8
(test-env) ~/condaexpts$ source activate test-env
(test-env) ~/condaexpts$ pip install numpy==1.12.0 llvmlite==0.15 numba==0.30.1
(test-env) ~/condaexpts$ find $CONDA_PREFIX | grep libllvmlite
/home/ubuntu/condaexpts/m3/envs/test-env/lib/python3.5/site-packages/llvmlite/binding/libllvmlite.so
If this file is not present in the test-env, then something went wrong while installing llvmlite.
Also, think about this approach the other way round. You don't need to have a requirements file separate from conda environment file. You can have both dependencies in the conda environment file itself:
(test-env) ~/condaexpts$ conda env export
name: test-env
channels:
- !!python/unicode
'numba'
- !!python/unicode
'defaults'
dependencies:
- !!python/unicode
'openssl=1.0.2k=0'
- !!python/unicode
'pip=9.0.1=py35_1'
- !!python/unicode
'python=3.5.2=0'
- !!python/unicode
'readline=6.2=2'
- !!python/unicode
'setuptools=27.2.0=py35_0'
- !!python/unicode
'sqlite=3.13.0=0'
- !!python/unicode
'tk=8.5.18=0'
- !!python/unicode
'wheel=0.29.0=py35_0'
- !!python/unicode
'xz=5.2.2=1'
- !!python/unicode
'zlib=1.2.8=3'
- !!python/unicode
'llvmdev=3.8.1=7'
- !!python/unicode
'system=5.8=2'
- pip:
- llvmlite==0.15.0
- numba==0.30.1
- numpy==1.12.0
prefix: !!python/unicode '/home/ubuntu/condaexpts/m3/envs/test-env'
On second note, you can install the pre-built binaries required from the 'numba' conda channel itself. With:
(root) ~/condaexpts$ ./Miniconda3-latest-Linux-x86_64.sh -b -p m3
(root) ~/condaexpts$ source ./m3/bin/activate
(root) ~/condaexpts$ conda create -n test-env -c numba python=3.5.2 llvmdev=3.8 numba=0.30.1 llvmlite=0.15.0
(root) ~/condaexpts$ source activate test-env
(test-env) ~/condaexpts$ python
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:53:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numba
>>> numba.__version__
'0.30.1'

Categories