how to install python3-tk in centos? - python

I need to install python3-tk in order to use matplotlib.
I have tried:
(python_3.4_numerical) [lpuggini#machinelearn-1 ~]$ sudo yum install python3-tk
[sudo] password for lpuggini:
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.clouvider.net
* epel: epel.check-update.co.uk
* extras: mirror.sov.uk.goscomb.net
* updates: mirrors.clouvider.net
No package python3-tk available.
Error: Nothing to do
(python_3.4_numerical) [lpuggini#machinelearn-1 ~]$
but it is not working.
How can I fix it?
EDIT:
Installing from pip does not work:
(python_3.4_numerical) [lpuggini#machinelearn-1 ~]$ pip install pygtk
Collecting pygtk
Using cached pygtk-2.24.0.tar.bz2
Complete output from command python setup.py egg_info:
********************************************************************
* Building PyGTK using distutils is only supported on windows. *
* To build PyGTK in a supported way, read the INSTALL file. *
********************************************************************
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-nzjsuhx3/pygtk/
(python_3.4_numerical) [lpuggini#machinelearn-1 ~]$

tkinter is available in coreos as tkinter package. You can install it with
sudo yum install tkinter
Once it is done, you can import and use it as usual.
>>> import tkinter
>>> tkinter._test()
For Python 3, you can install it with
sudo yum install python3-tkinter
As some users mentioned, it is available as python36u-tkinter or python34-tkinter depending on OS.
sudo yum install python34-tkinter
sudo yum install python36u-tkinter

In Centos 7 you can use:
yum install python36-tkinter

I solved the same problem using these two commands 100%
sudo yum -y update
sudo yum -y install python36u-tkinter

Try the following command.
sudo yum install python3-tkinter
Now Test in your terminal:
>>> import tkinter
>>> tkinter._test()

I believe tk come with python by default. If so, have you look to reinstall your python 3.4. (I prefer ver3.5). Procedures are mentioned in this website.
Steps:
Download python version
wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tar.xz
Install decoding tool if you don't have: sudo yum install xz-libs
Decode the xz encodeing xz -d Python-3.5.3.tar.xz
Uncompress the decoded file tar -xvf Python-3.5.3.tar
Move the desired directory to install python cd Python-3.5.3
Configure python file ./configure
Build using make
Install using make altinstall
Check if tkinter works. A tk window should pop out. Open a terminal and type the following:
python3.5
import tkinter as tk
root = tk.Tk()
The website also has other instructions for installing setuptools and pip which are very useful.

I spent lots of time on this problem, here is my solution effectively:
yum -y install tkinter tcl-devel tk-devel
to your python directory:
vim ......./Python3.5.1/Modules/Setup.dist
Remove comments from these lines:
_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \
-L/usr/local/lib \
-I/usr/local/include \
-ltk8.5 -ltcl8.5 \ # default is 8.2 and you should change it to the version you installed in step1
-lX11
3.
./configure
make && make install
Result:
[root#localhost Python-3.5.1]# python3
Python 3.5.1 (default, Jun 19 2017, 22:43:42)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>

It depends on your python version. For python 3.4 it's sudo yum install python34-tkinter

Or, maybe you are using software collections (SCL), then install the proper tkinter.
search tkinter:
yum search tkinter
install proper tkinter such as
yum install rh-python36-python-tkinter
Depending on which repository you are using for python, you have different "default" tkinter.

I tried all the other solutions here and none of them work for me.
After a bit of research, I found the right package that worked for me.
sudo yum update
sudo yum install rh-python36-python-tkinter
if you use a different version of python3 try searching for your package as I did with
sudo yum search tkinter
and see what option fits your version

for python 3.9 version and on RHEL:
$ sudo yum install python39-tkinter

Related

UserWarning: Could not import the lzma module. Your installed Python is incomplete

After Installing Google Cloud Bigquery Module, if I import the module into python code. I see this warning message. Happening to me in python 3.7.3 Virtualenv.
Tried to reinstall GCP bigquery module
Expectation-in python code if we write" from google.cloud import bigquery ".Should not result in any error or messege.
import os
import sys
import logging
from datetime import datetime
from google.cloud import bigquery
/home/informatica/.local/lib/python3.7/site-packages/pandas/compat/__init__.py:84: UserWarning: Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma compression will result in a RuntimeError.
warnings.warn(msg)
exit()
If you compile Python from source, you must have the lzma-dev package installed, or it will not be built into python.
For ubuntu: sudo apt-get install liblzma-dev
For centos: yum install -y xz-devel
Then configure && make && make install
I used other good answers from here and didn't solve the problem (Ubuntu 18.04, Python3.8), still get this warning.
Actually there is one more package is needed to be installed to solve the problem:
sudo apt-get install lzma
So the whole pipeline (run in the python source code folder):
sudo apt-get install liblzma-dev
sudo apt-get install lzma
./configure --enable-optimizations
sudo make
sudo make altinstall
On MacOS and pyenv (https://realpython.com/intro-to-pyenv/), I was able to have this warning go away by having xz installed with homebrew. Using version python 3.6.9 as an example
brew install xz && pyenv install 3.6.9
To use installed python, one needs to add this into .bash_profile
eval "$(pyenv init -)"
and start using it by running
pyenv global 3.6.9
On macOS, if you manage your python with pyenv and package with homebrew, you need to install "xz" first:
brew install xz
After installing xz, you can install python 3.8 by (I'm using 3.8.2 as an example:
pyenv install 3.8.2
Above will fix the problem.
If you are using centos and compile python from source, you can install from following commands
For centos: sudo yum install -y xz-devel
Recompile python from source code
cd Python-3.8*/
./configure --enable-optimizations
sudo make altinstall
This solution* worked on my setup (Apple M1 with pyenv):
CFLAGS="-I$(brew --prefix xz)/include" LDFLAGS="-L$(brew --prefix xz)/lib" pyenv install 3.9.4
*Edit (2023-02-08): Link removed following the helpful comment from Martin Delille.
See last comment on https://github.com/pandas-dev/pandas/issues/27532
brew install xz # To pick up liblzma
prefix=$(brew --prefix)
export LDFLAGS="-L$prefix/opt/xz/lib $LDFLAGS"
export CPPFLAGS="-I$prefix/opt/xz/include $CPPFLAGS"
export PKG_CONFIG_PATH="$prefix/opt/xz/lib/pkgconfig:$PKG_CONFIG_PATH"
# YOU CANNOT HAVE THE GNUBINS in your PATH when you run this
PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.9.2
python3 -c "import lzma" # should work and not throw "cannot import _lzma"
What solved for me:
sudo apt-get install libbz2-dev
sudo cp /usr/lib/python3.8/lib-dynload/_bz2.cpython-38-x86_64-linux-gnu.so/usr/local/lib/python3.8/
sudo cp /usr/lib/python3.8/lib-dynload/_lzma.cpython-38-x86_64-linux-gnu.so /usr/local/lib/python3.8/
I did brew install xz and reinstalled everything, but that didn't do it for me.
What helped me was to add correct linkage for xz as well:
export LDFLAGS="-L$(brew --prefix xz)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib"
export CPPFLAGS="-I$(brew --prefix xz)/include -I$(brew --prefix readline)/include -I$(brew --prefix zlib)/include -I$(xcrun --show-sdk-path)/usr/include"
I found the solution from: https://github.com/pandas-dev/pandas/issues/28219
I just ran: CPPFLAGS="-I$(brew --prefix xz)/include" pyenv install 3.10.0
OS: Monterey
M1 chip
pyenv
python 3.10.0
I see that
yum install -y lzma
Also runs without errors.
My OS is : CentOS 8.X
Step to step run command below, then fix the problem:
sudo yum install -y xz-devel
cd Python-3.8.5
sudo ./configure --prefix=/usr/local/python3.8.5 --enable-optimizations --with-ssl
sudo make
sudo make install
I had built Python 3.8 from source on Debian 10 and some times couldn't start mlflow server at all and sometimes got warnings albeit successful launches and also every pandas import gave me this warning.
Here's what worked for me:
purged the existing installation.
did sudo apt install libncurses-dev libgdbm-dev libz-dev tk-dev libsqlite3-dev libreadline-dev liblzma-dev libffi-dev libssl-dev
built python from source again.
I never got the warning again and had no problems whatsoever.
I'd like to provide some info on what "xz" and "lzma" are.
man xz:
xz, unxz, xzcat, lzma, unlzma, lzcat - Compress or decompress .xz and .lzma files
https://www.nongnu.org/lzip/xz_inadequate.html :
xz is a container format which currently contains another container format (LZMA2), which in turn contains a mix of LZMA data and uncompressed data.
Well, as far as I understand, lzma is a compression algorithm and xz is the file format.
For example, on https://www.python.org/downloads/release/python-3106/ , there's XZ compressed source tarball compared to Gzipped source tarball .
So if you don't need to deal with the .xz files with pandas, you could just ignore the warning and keep going. Otherwise you need to reinstall python and you alreay have lzma libraries installed in the system. The lzma library's package name varies in different distros/OS. For example, on mac it's xz and ubuntu it's liblzma-dev.
Also see:
https://pandas.pydata.org/pandas-docs/dev/whatsnew/v0.25.1.html#io-and-lzma
https://github.com/pandas-dev/pandas/blob/b5958ee1999e9aead1938c0bba2b674378807b3d/pandas/_testing.py#L245
lzma vs zlib:
https://joblib.readthedocs.io/en/latest/auto_examples/compressors_comparison.html

RHEL/Pyenv: No module named '_tkinter'

I'm trying to use Matplotlib on RHEL using a pyenv installed version of python 3.6.5. (installed using the following command)
→ pyenv install 3.6.5
Installing Python-3.6.5...
python-build: use readline from homebrew
Installed Python-3.6.5 to /home/swp1g17/.pyenv/versions/3.6.5
→ pyenv global 3.6.5
I'm presented with the following error, and have found many questions that have a similar issue:
Python 3.6.5 (default, Apr 5 2018, 17:22:36)
[GCC 5.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/swp1g17/.pyenv/versions/3.6.5/lib/python3.6/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
However the suggested solution is usually to install tkinter using a package manager.
However I've tried installing:
2872 sudo yum install rh-python36-python-tkinter
2873 sudo yum install rh-python35-python-tkinter
2874 sudo yum install rh-python34-python-tkinter
2891 sudo yum install tkinter
2893 sudo yum install python36-tkinter
2902 sudo yum install gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel gdbm-devel ncurses-devel gl..
2916 sudo yum install tkinter.x86_64 rh-python36-python-tkinter.x86_64 rh-python35-python-tkinter.x86_64 rh-python34-python-tkinter.x86_64 p..
2921 sudo yum install tcl
2933 sudo yum install tk-devel
2934 sudo yum install tk
3000 sudo yum install tkinter
3026 sudo yum install tix
3031 sudo yum install tk
3032 sudo yum install tk-devel
> 3033 sudo yum install tcl-devel
with each already having been installed or making no difference (having rebuilt python each time a new package was installed.
The system python is able to locate tkinter:
→ /usr/bin/python3.6
Python 3.6.3 (default, Jan 4 2018, 16:40:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>
so I'm unsure how to install python using pyenv and have it use the same version of tkinter?
UPDATE:
Having found that build configuration options can be set using $PYTHON_CONFIGURE_OPTS I've tried specifying the library locations using (for linuxbrew downloaded tcl/tk):
export PYTHON_CONFIGURE_OPTS="--with-tcltk-includes=-I/home/linuxbrew/.linuxbrew/opt/tcl-tk/include --with-tcltk-libs=-L/home/linuxbrew/.linuxbrew/opt/tcl-tk/lib"
pyenv install 3.6.5
and (using system tcl/tk):
export PYTHON_CONFIGURE_OPTS="--with-tcltk-includes=-I/usr/include --with-tcltk-libs=-L/usr/lib64"
pyenv install 3.6.5
each with no luck. System tcl/tk was found using:
→ whereis tcl
tcl: /usr/lib64/tcl8.5 /usr/include/tcl.h /usr/share/tcl8.5
→ whereis tcl
tcl: /usr/lib64/tcl8.5 /usr/include/tcl.h /usr/share/tcl8.5
Below is my step-by-step howto using pyenv 1.2.11 on Ubuntu 19.04 and Fedora 29:
Install pyenv
Using the installer
git clone https://github.com/pyenv/pyenv-installer
chmod +x pyenv-installer/bin/pyenv-installer
pyenv-installer/bin/pyenv-installer
By hand
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
Setup pyenv
$ cat >> ~/.bashrc
# Load pyenv automatically
export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
Ctrl + D
$ source ~/.bashrc
$ pyenv --version
pyenv 1.2.11-8-g070e1c85
Install dependencies
Ubuntu 19.04 Disco Dingo
sudo apt install tk-dev # <-- This has fixed my issue
sudo apt install libbz2-dev
sudo apt install libreadline-dev
sudo apt install libsqlite3-dev
Fedora 29
sudo dnf install tk-devel # <-- This may fix your issue
sudo dnf install libbz2-dev
sudo dnf install readline-devel
sudo dnf install libsqlite3x-devel
sudo dnf install openssl-devel
sudo dnf install make
Install Python-3.6.8 using pyenv
pyenv install 3.6.8
Check installation
$ pyenv local 3.6.8 # Create file .python-version
$ python --version
Python 3.6.8
Install modules
python -m pip install --user --upgrade pip
python -m pip install --user pipenv
...
Example of pipenv usage
cd /path/where/your/Pipfile/is/located/
pyenv local 3.6.8
python -m pipenv --rm # first time: No virtualenv has been created...
python -m pipenv update --dev
python -m pipenv run python -m nose # my unit tests

Python3: ImportError: No module named '_ctypes' when using Value from module multiprocessing

I am using Ubuntu and have installed Python 2.7.5 and 3.4.0. In Python 2.7.5 I am able to successfully assign a variable x = Value('i', 2), but not in 3.4.0. I am getting:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/multiprocessing/context.py", line 132, in Value
from .sharedctypes import Value
File "/usr/local/lib/python3.4/multiprocessing/sharedctypes.py", line 10, in <
module>
import ctypes
File "/usr/local/lib/python3.4/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ImportError: No module named '_ctypes'
I just updated to 3.3.2 through installing the source of 3.4.0. It installed in /usr/local/lib/python3.4.
Did I update to Python 3.4 correctly?
One thing I noticed that Python 3.4 is installed in usr/local/lib, while Python 3.3.2 is still installed in usr/lib, so it was not overwritten.
Installing libffi-dev and re-installing python3.7 fixed the problem for me.
to cleanly build py 3.7 libffi-dev is required or else later stuff will fail
If using RHEL/Fedora:
yum install libffi-devel
or
sudo dnf install libffi-devel
If using Debian/Ubuntu:
sudo apt-get install libffi-dev
On a fresh Debian image, cloning https://github.com/python/cpython and running:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus
sudo apt-get install libncursesw5-dev libgdbm-dev libc6-dev
sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
sudo apt-get install libssl-dev openssl
sudo apt-get install libffi-dev
Now execute the configure file cloned above:
./configure
make # alternatively `make -j 4` will utilize 4 threads
sudo make altinstall
Got 3.7 installed and working for me.
SLIGHT UPDATE
Looks like I said I would update this answer with some more explanation and two years later I don't have much to add.
this SO post explains why certain libraries like python-dev might be necessary.
this SO post explains why one might use the altinstall as opposed to install argument in the make command.
Aside from that I guess the choice would be to either read through the cpython codebase looking for #include directives that need to be met, but what I usually do is keep trying to install the package and just keep reading through the output installing the required packages until it succeeds.
Reminds me of the story of the Engineer, the Manager and the Programmer whose car rolls down a hill.
If you use pyenv and get error "No module named '_ctypes'" (like i am) on Debian/Raspbian/Ubuntu you need to run this commands:
sudo apt-get install libffi-dev
pyenv uninstall 3.7.6
pyenv install 3.7.6
Put your version of python instead of 3.7.6
Detailed steps to install Python 3.7 in CentOS or any redhat linux machine:
Download Python from https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
Extract the content in new folder
Open Terminal in the same directory
Run below code step by step :
sudo yum -y install gcc gcc-c++
sudo yum -y install zlib zlib-devel
sudo yum -y install libffi-devel
./configure
make
make install
Thought I'd add the Centos installs:
sudo yum -y install gcc gcc-c++
sudo yum -y install zlib zlib-devel
sudo yum -y install libffi-devel
Check python version:
python3 -V
Create virtualenv:
virtualenv -p python3 venv
On my Ubuntu 18.04 machine, I had the common problem of python not finding _ctypes with the pyenv installed python.
In my case libffi-dev was already installed. Installing cpython from source, as suggested by #MikeiLL, didn't help either.
Turned out to be an homebrew issue.
ajkerrigans suggested solution on pyenvs github issues solved this problem for me.
Solution summary: Tell pyenv to build Python using the Homebrew-managed GCC, with a command like:
CC="$(brew --prefix gcc)/bin/gcc-11" \
pyenv install --verbose 3.10.0
This assumes that any build dependencies have also been installed via Homebrew as specified in the pyenv wiki. As of this writing, that looks like this for Homebrew on Linux:
brew install bzip2 libffi libxml2 libxmlsec1 openssl readline sqlite xz zlib
This solved the same error for me on Debian:
sudo apt-get install libffi-dev
and compile again
Reference: issue31652
None of the solution worked. You have to recompile your python again; once all the required packages were completely installed.
Follow this:
Install required packages
Run ./configure --enable-optimizations
https://gist.github.com/jerblack/798718c1910ccdd4ede92481229043be
I run into this error when I tried to install Python 3.7.3 in Ubuntu 18.04 with next command: $ pyenv install 3.7.3.
Installation succeeded after running $ sudo apt-get update && sudo apt-get install libffi-dev (as suggested here).
The issue was solved there.
Based on this answer, just copy-paste into the terminal.
First run:
sudo apt-get -y update
then:
sudo apt-get -y upgrade
sudo apt-get -y dist-upgrade
sudo apt-get -y install build-essential python-dev python-setuptools python-pip python-smbus
sudo apt-get -y install libncursesw5-dev libgdbm-dev libc6-dev
sudo apt-get -y install zlib1g-dev libsqlite3-dev tk-dev
sudo apt-get -y install libssl-dev openssl
sudo apt-get -y install libffi-dev
PS: You can just copy-paste the whole chunk into the terminal in one go.
In my case what was causing all sorts of Python installation issues including the one having to do with _ctypes and libffi was Homebrew on Linux / Linuxbrew. pyenv was happy again once brew was no longer in the $PATH.
Refer to this thread or this thread, for customized installation of libffi, it is difficult for Python3.7 to find the library location of libffi. An alternative method is to set the CONFIGURE_LDFLAGS variable in the Makefile, for example CONFIGURE_LDFLAGS="-L/path/to/libffi-3.2.1/lib64".
My solution:
Installing libffi-dev with apt-get didn't help.
But this helped: Installing libffi from source and then installing Python 3.8 from source.
My configuration:
Ubuntu 16.04 LTS
Python 3.8.2
Step by step:
I got the error message "ModuleNotFoundError: No module named '_ctypes'" when starting the debugger from Visual Studio Code, and when running python3 -c "import sklearn; sklearn.show_versions()".
download libffi v3.3 from https://github.com/libffi/libffi/releases
install libtool: sudo apt-get install libtool
The file README.md from libffi mentions that autoconf and automake are also necessary. They were already installed on my system.
configure libffi without docs:
./configure --disable-docs
make check
sudo make install
download python 3.8 from https://www.python.org/downloads/
./configure
make
make test
make install
After that my python installation could find _ctypes.
CentOS without root
Install libffi-3.2 (Do NOT use libffi-3.3)
wget ftp://sourceware.org/pub/libffi/libffi-3.2.tar.gz
tar -xzf libffi-3.2.tar.gz
cd libffi-3.2/
./configure --prefix=$YOUR_LIBFFI_DIR
make && make install
Install Python3
./configure --prefix=$YOUR_PATH/python/3.7.10 LDFLAGS=-L${YOUR_LIBFFI_DIR}/lib64 PKG_CONFIG_PATH=${YOUR_LIBFFI_DIR}/lib/pkgconfig --enable-shared
make && make install
Thanks for JohnWSteill
I was having the same problem. None of the above solutions worked for me. The key challenge was that I didn't have the root access. So, I first download the source of libffi. Then I compiled it with usual commands:
./configure --prefix=desired_installation_path_to_libffi
make
Then I recompiled python using
./configure --prefix=/home/user123/Softwares/Python/installation3/ LDFLAGS='-L/home/user123/Softwares/library/libffi/installation/lib64'
make
make install
In my case, 'home/user123/Softwares/library/libffi/installation/lib64' is path to LIBFFI installation directory where libffi.so is located. And, /home/user123/Softwares/Python/installation3/ is path to Python installation directory. Modify them as per your case.
If you don't mind using Miniconda, the necessary external libraries and _ctypes are installed by default. It does take more space and may require using a moderately older version of Python (e.g. 3.7.6 instead of 3.8.2 as of this writing).
You have to load the missing php3 (Python3) modules from the package manager.
If you have Ubuntu I recommend the Synaptic Package Manager:
sudo apt-get install synaptic
There you can simply search for the missing modules. search for ctypes and install all the packages. Then go to your Python dir and do
./configure
make install.
This should solve your problem.
How to install Python from source without libffi in /usr/local?
Download libffi from github and install to /path/to/local
Download python source code and compile with the following configuration:
export PKG_CONFIG_PATH=/path/to/local/lib/pkgconfig
./configure --prefix=/path/to/python \
LDFLAGS='-L/path/to/local/lib -Wl,-R/path/to/local/lib' \
--enable-optimizations
make
make install
I am using MAC M1 and I had this error:
... __boot__.py", line 30, in <module> import ctypes
and something was said about the file libffi.8.dylib
I downloaded this thing on Anaconda and now everything works:
https://anaconda.org/wakari/libffi
I inform you, since much of the above is either not for MAC or outdated, my Python is on Anaconda version 3.10.4
Application file created with py2app works now!!
If your issue is with the VSCODE DEBUGGER, check your currently selected python interpreter. I had both python3.10.9 and python3.10.6 installed; however, the former was probably missing some dependencies so I switched to the latter(my OS default interpreter) which solved the issue.
To change your python interpreter in VSCODE:
Hold ctrl+shift+P
Search Python:Select Interpreter and try your OS default version(The version you get when you run python3 --version
If the issue is still not resolved, run sudo apt-get install libffi-dev.
If you are doing something nobody here will listen you about because "you're doing it the wrong way", but you have to do it "the wrong way" for reasons too asinine to explain and also beyond your ability to control, you can try this:
Get libffi and install it into your user install area the usual way.
git clone https://github.com/libffi/libffi.git
cd libffi
./configure --prefix=path/to/your/install/root
make
make install
Then go back to your Python 3 source and find this part of the code in setup.py at the top level of the python source directory
ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
if not ffi_inc or ffi_inc[0] == '':
ffi_inc = find_file('ffi.h', [], inc_dirs)
if ffi_inc is not None:
ffi_h = ffi_inc[0] + '/ffi.h'
if not os.path.exists(ffi_h):
ffi_inc = None
print('Header file {} does not exist'.format(ffi_h))
ffi_lib = None
if ffi_inc is not None:
for lib_name in ('ffi', 'ffi_pic'):
if (self.compiler.find_library_file(lib_dirs, lib_name)):
ffi_lib = lib_name
break
ffi_lib="ffi" # --- AND INSERT THIS LINE HERE THAT DOES NOT APPEAR ---
if ffi_inc and ffi_lib:
ext.include_dirs.extend(ffi_inc)
ext.libraries.append(ffi_lib)
self.use_system_libffi = True
and add the line I have marked above with the comment. Why it is necessary, and why there is no way to get configure to respect '--without-system-ffi` on Linux platforms, perhaps I will find out why that is "unsupported" in the next couple of hours, but everything has worked ever since. Otherwise, best of luck... YMMV.
WHAT IT DOES: just overrides the logic there and causes the compiler linking command to add "-lffi" which is all that it really needs. If you have the library user-installed, it is probably detecting the headers fine as long as your PKG_CONFIG_PATH includes path/to/your/install/root/lib/pkgconfig.

ImportError: No module named scipy

I am using Python 2.7 and trying to get PyBrain to work.
But I get this error even though scipy is installed -
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/PyBrain-0.3.1-
py2.7.egg/pybrain/__init__.py", line 1, in <module>
from pybrain.structure.__init__ import *
File "/usr/local/lib/python2.7/site-packages/PyBrain-0.3.1-py2.7.egg/pybrain/structure/__init__.py", line 1, in <module>
from pybrain.structure.connections.__init__ import *
File "/usr/local/lib/python2.7/site-packages/PyBrain-0.3.1-py2.7.egg/pybrain/structure/connections/__init__.py", line 1, in <module>
from pybrain.structure.connections.full import FullConnection
File "/usr/local/lib/python2.7/site-packages/PyBrain-0.3.1-py2.7.egg/pybrain/structure/connections/full.py", line 3, in <module>
from scipy import reshape, dot, outer
ImportError: No module named scipy
I have installed scipy using this command -
sudo apt-get install python-scipy
I get -
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-scipy is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
What should I do?
Try to install it as a python package using pip. You said you already tried:
sudo apt-get install python-scipy
Now run:
pip install scipy
I ran both and it worked on my Debian-based box.
To ensure easy and correct installation for python use pip from the get go
To install pip:
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python2 get-pip.py # for python 2.7
$ sudo python3 get-pip.py # for python 3.x
To install scipy using pip:
$ pip2 install scipy # for python 2.7
$ pip3 install scipy # for python 3.x
For windows users:
I found this solution after days. Firstly which python version you want to install?
If you want for Python 2.7 version:
STEP 1:
scipy‑0.19.0‑cp27‑cp27m‑win32.whl
scipy‑0.19.0‑cp27‑cp27m‑win_amd64.whl
numpy‑1.11.3+mkl‑cp27‑cp27m‑win32.whl
numpy‑1.11.3+mkl‑cp27‑cp27m‑win_amd64.whl
If you want for Python 3.4 version:
scipy‑0.19.0‑cp34‑cp34m‑win32.whl
scipy‑0.19.0‑cp34‑cp34m‑win_amd64.whl
numpy‑1.11.3+mkl‑cp34‑cp34m‑win32.whl
numpy‑1.11.3+mkl‑cp34‑cp34m‑win_amd64.whl
If you want for Python 3.5 version:
scipy‑0.19.0‑cp35‑cp35m‑win32.whl
scipy‑0.19.0‑cp35‑cp35m‑win_amd64.whl
numpy‑1.11.3+mkl‑cp35‑cp35m‑win32.whl
numpy‑1.11.3+mkl‑cp35‑cp35m‑win_amd64.whl
If you want for Python 3.6 version:
scipy‑0.19.0‑cp36‑cp36m‑win32.whl
scipy‑0.19.0‑cp36‑cp36m‑win_amd64.whl
numpy‑1.11.3+mkl‑cp36‑cp36m‑win32.whl
numpy‑1.11.3+mkl‑cp36‑cp36m‑win_amd64.whl
Link: [click[1]
Once finish installation, go to your directory.
For example my directory:
cd C:\Users\asus\AppData\Local\Programs\Python\Python35\Scripts>
pip install [where/is/your/downloaded/scipy_whl.]
STEP 2:
Numpy+MKL
From same web site based on python version again:
After that use same thing again in Script folder
cd C:\Users\asus\AppData\Local\Programs\Python\Python35\Scripts>
pip3 install [where/is/your/downloaded/numpy_whl.]
And test it in python folder.
Python35>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
>>>import scipy
I had a same problem because I installed both of python2.7 and python3. when I run program with python3 I received same error.
I install scipy with this command and problem has been solved:
sudo apt-get install python3-scipy
if you are using pycharm go to settings and in project interpreter sub-tab click on "+" sign next to list and in the search bar in there search name "scipy" and install the package.
If you need to get scipy in your Python environment on Windows you can get the *.whl files here:
https://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy
Remember that you need to install numpy+mkl before you can install scipy.
https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
When you have downloaded the correct *.whl files just open a command prompt in the download directory and run pip install *.whl.
For Windows User :
pip install -U scipy
I recommend you to remove scipy via
apt-get purge scipy
and then to install it by
pip install scipy
If you do both then you might confuse you deb package manager due to possibly differing versions.
Try to install it as a python package using pip as follows
$ sudo apt-get install python-scipy
If you want to run a python 3.x script, install scipy by:
$ pip3 install scipy
Otherwise install it by:
$ pip install scipy
This may be too basic (and perhaps assumable), but -
Fedora users can use:
sudo dnf install python-scipy
and then (For python3.x):
pip3 install scipy
or (For python2.7):
pip2 install scipy
Your python don't know where you installed scipy. add the scipy path to PYTHONPATH and I hope it will solve your problem.
My problem was that I spelt one of the libraries wrongly when installing with pip3, which ended up all the other downloaded libaries in the same command not being installed. Just run pip3 install on them again and they should be installed from their cache.
Use sudo pip install scipy to install the library so It cannot ask for permissions later
in previous steps by #user5747799, it do not work directly but instead change the URL (https://bootstrap.pypa.io/pip/2.7/get-pip.py) and now spicy work very well on Ubuntu 20.04
Also o follow steps to switch between version from https://www.fosslinux.com/39384/switching-between-python-2-and-3-versions-on-ubuntu-20-04.htm
To install pip using alternative URL:
$ wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
$ sudo python2 get-pip.py.2 # for python 2.7 (or verify the result of previous step)
$ sudo python3 get-pip.py # for python 3.x
To install scipy using pip:
$ pip2 install scipy # for python 2.7
$ pip3 install scipy # for python 3.x
in order to verify
$ python
then
>>> import scipy
with no errors to show.
for Mac run below command to install scipy
$ brew install scipy
$ pip install scipy
Try forcing a reinstall of scipy:
python3 -m pip install scipy --force-reinstall
for python3 below command to install scipy
python3 -m pip install scipy

Python unable to locate gmpy library

I want to use a python script which imports gmpy. However, python always tells me:
ImportError: No module named 'gmpy'
I am on Ubuntu 14.04 i686 and I tried to install gmpy over various ways:
sudo pip install gmpy
sudo pip install gmpy2
sudo apt-get install python-gmpy*
sudo apt-get install python2.7-gmpy*
sudo apt-get install python3-gmpy*
I also followed the officiel instruction on building gmpy from source (I also compiled MPC, MPFR, and GMP from source for this reason).
Obviously I am using python 3.4.0:
$ python
$ Python 3.4.0 (default, Apr 11 2014, 13:05:18)
[GCC 4.8.2] on linux
What am I missing such that python is not able to find the gmpy libs?
Any of the following solutions solved the problem:
sudo pip3 install gmpy (I executed the wrong pip as I am using python3)
or
$ python2.7 script.py (Or simply use python2 interpreter)
apt-get -f install
pip2 install gmpy
Done.

Categories

Resources