Trying to install an old python app, getting a libevent error - python

There is an old python app that I want to install on ubuntu.
When I run:
python setup.py install
I get this error:
/tmp/easy_install-s6CQJl/event-0.4.2/setup.py:23: UserWarning: Could not find libevent
warnings.warn("Could not find libevent")
event.c:4:20: fatal error: Python.h: No such file or directory
I have installed
build-essential
python-setuptools
libevent-dev
Is there something else I am missing?

event.c:4:20: fatal error: Python.h: No such file or directory
It looks like you need the Python development headers. Try
sudo apt-get install python-dev
Edit:
Hookbox can be successfully installed on Ubuntu 18.04 with a relatively modern Python 2.7. Here's a complete installation process:
Install OS-level dependencies
sudo add-apt-repository universe # Required for old libevent
sudo apt-get update
sudo apt-get install \
build-essential \
libevent1-dev \
libevent-1.4-2 \
python \
python-dev \
python-setuptools
Clone the source code somewhere convenient
git clone git://github.com/hookbox/hookbox.git
Install Hookbox
cd hookbox
# Ideally we should install Hookbox in a virtualenv
#
# Here is one way to do that
sudo apt-get install virtualenv
virtualenv env
source env/bin/activate
python setup.py install
If you use the virtualenv method outlined above you'll be able to run hookbox --help to see that it's working.
You can exit the virtualenv with deactivate (and still run hookbox by providing an absolute path to path/to/hookbox/env/bin/hookbox) and re-enter it with source path/to/hookbox/env/bin/activate, at which point hookbox should be on your $PATH.
If you choose not to use a virtualenv you'll need to use sudo python setup.py install here. That's not recommended as you'll be mixing manually installed Python packages with OS-supplied ones.

Related

Unable to install python-pip module [duplicate]

I am trying to install mininet-wifi. After downloading it, I have been using the following command to install it:
sudo util/install.sh -Wlnfv
However, I keep getting the error:
E: Unable to locate package python-pip
I have tried multiple times to download python-pip. I know mininet-wifi utilizes python 2 instead of python 3. I have tried to download python-pip using the command:
sudo apt-get install python-pip
But that leads to the same error:
E: Unable to locate package python-pip
Pip for Python 2 is not included in the Ubuntu 20.04 repositories. You need to install pip for Python 2 using the get-pip.py script.
1. Start by enabling the universe repository:
sudo add-apt-repository universe
2. Update the packages index and install Python 2:
sudo apt update
sudo apt install python2
3. Use curl to download the get-pip.py script:
curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py
4. Once the repository is enabled, run the script as sudo user with python2 to install pip :
sudo python2 get-pip.py
If an error occurs, as a fallback, the specific 2.7 version of get-pip.py can be used:
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
Pip will be installed globally. If you want to install it only for your user, run the command without sudo. The script will also install setuptools and wheel, which allow you to install source distributions
Verify the installation by printing the pip version number:
pip2 --version
The output will look something like this:
pip 20.0.2 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
Since Python 2 is past its end-of-life, few packages for Python2 are included in 20.04. You have to install pip for Python 2 manually:
First, install Python 2:
sudo apt install python2
Then, follow https://pip.pypa.io/en/stable/installing/ , using python2:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python2 get-pip.py
You can run the second step with sudo. If you don't use sudo, you'll need to change PATH, as suggested by the installation message. Alternatively, and possibly better (since it doesn't change PATH), use
python2 -m pip
whenever you need pip2.
In my case, the curl command for downloading get-pip.py gave a syntax error on running sudo python get-pip.py.
But manual download by visiting https://bootstrap.pypa.io/ and downloading get-pip.py worked fine for me.
I've found that creating a virtualenv for Python 2.7 installs also pip
$ virtualenv -p python2 venv
$ . venv/bin/activate
$ pip --version
pip 20.0.2 from /home/.../venv/lib/python2.7/site-packages/pip (python 2.7)
Put python3 instead ${PYPKG} in line 202, and instead python-pip in line 596 in file install.sh of mininet-wifi.
To solve the problem of:
E: Unable to locate package python-pip
Run the package update index cmd:
sudo apt update
If not that, then python-pip-whl (which is also a package installer) is available in the universe repository, make sure that's installed and then run:
sudo apt-get install python-pip-whl
I specifically needed a Dockerfile file and this is what I have put inside so that it works without errors, I hope it will help someone.
This is Dockerfile file:
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python3 python3-dev
WORKDIR /app
COPY . /app
ENV DEBUG=True
EXPOSE 80

pyvenv not working because ensurepip is not available

I upgraded from ubuntu 14.04 to ubuntu 16.04 a few days ago.
When I try to create a virtual env by using
pyvenv .venv
or
python3 -m venv .venv
There is an error:
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt-get install python3-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/home/user/.venv/bin/python3.5', '-Im', 'ensurepip', '--upgrade', '--default-pip']
I tried running both
sudo apt-get install python3-venv
and
sudo apt-get install python3.5-venv
but it did not solve my problem.
try installing python3.6-venv:
sudo apt-get install python3.6-venv
It seems that it was a locale problem. Solved by executing:
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales
found on this thread Python locale error: unsupported locale setting
Under Windows Linux Subsystem and Ubuntu 18.04, this was caused by my not having upgraded recently.
I ran:
sudo apt update
sudo apt upgrade
Then sudo apt install python3-venv worked.
Note that I had also tried the UTF-8 solution beforehand (I made it part of my .bashrc), so that could have been a contributing factor.
One of the other answers fixed it for me last time, but with Python 3.7 I had to do:
apt install python3-pip python3-setuptools python3.7-venv
Followed by
python3.7 -m venv /path/to/venv
Resolved similar problems on Ubuntu18 when came upon this answer. It is similar to the one that worked for #Niko Rikken, except it doesn't really need any new PPA's and "python3.8-distutils" package. I was installing new python3.8 environment with venv and I already had "python3-venv" installed and up to date, so my solution was to install only "python3.8-venv":
% sudo apt-get install python3.8-venv
And that got this lines working:
% python3.8 -m venv ~/envs/new_env
% source ~/envs/new_env/bin/activate
In my case the next steps worked:
Ubuntu 18.04.4 LTS
$ sudo apt-get install python3-venv python3.7-venv
$ python3.7 -m venv [your_path_to_virtual_env_here]
In case this helps anyone down the line, I was getting the same error on Ubuntu 18.04. Setting the locales didn't work and trying to install python3-venv gave the error:
$ sudo apt-get install python3-venv
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
python3-venv : Depends: python3.6-venv (>= 3.6.5-2~) but it is not going to be installed
Depends: python3 (= 3.6.5-3) but 3.6.7-1~18.04 is to be installed
E: Unable to correct problems, you have held broken packages.
And it looks like the apt repository had two versions of python:
$ apt list python3 -a
python3/bionic-updates,now 3.6.7-1~18.04 amd64 [installed]
python3/bionic 3.6.5-3 amd64
I tried to install Python3.6.5-3 but apt wanted to uninstall every dependency. I was able to solve the problem by installing Python3.7 and creating the venv with that:
$ sudo apt-get install python3.7 python3.7-venv
$ python3.7 -m venv my_venv
I encountered this problem on Ubuntu 18.04 for the recent release of Python-3.8. My solution was to add the Deadsnakes PPA which supplies the required python3.8-distutils package. The python3.8-venv package is already in the repository. Thanks to this blogpost:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.8
sudo apt install python3.8-distutils
sudo apt install python3.8-venv
Note: This is only a temporary solution. In the near future the required python3.8-distutils package will probably be available in the default Ubuntu repository.
Edit:
For Ubuntu 20.04 LTS the python3-distutils package is based on Python 3.8. As of yet there is no Python 3.8 package distutils package available for Ubuntu 18.04 LTS.
As mentioned in other comments on this thread, distutils might not be required. It was for my use-case, but please consider that solution before adding additional PPA's.
First, make a directory :
mkdir testing
Then, moved to this directory named testing :
cd testing
When you type following command in this directory:
python3 -m venv env
You got error like :
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt install python3.8-venv
Type the following command but before that keep an eye on the version of python you installed on the machine; in my case its python3.8
sudo apt install python3.8-venv
Now, we can create a virtual environment and store its tools in the "bhandari" folder .
python3 -m venv bhandari
Note: you can named this "bhandari" folder; anyname you like( Standard practice is to name it "env" ...)
Now to activate your virtual environment, from the directory of your folder, type the following command this will activate our virtual environment in the “bhandari” folder
source bhandari/bin/activate
If you have successfully activated your virtual environment, you should see the (bhandari) word indicating that we are working in a virtual environment.
After this, we can install anything that will be isolated from the rest of the system....
I was faced with the same problem and I am searching for a solution. It is about the problem:
ensurepip is disabled in Debian/Ubuntu for the system python.
And this my solution:
python3 -m venv myvenv --without-pip --system-site-packages
Try the following commands:
sudo apt install python-virtualenv
virtualenv --python=python3.6 myenv
These commands might work for you.
If you get any error like E: Unable to locate package python3-venv
Then try the following commands:
sudo apt install python3.6-venv
Python updated or Default python changed and venv already installed
the venv installed on your system is installed by your previous python version(let say python3.6). that's why venv is not working with current python version(lets say 3.8).
so first check your default python or python3 version,( suppose ur current version is python3.8).
reinstall virtual environment by mentioning current python version(3.8) as follow
sudo apt-get install python3.xx-venv >> replace xx with your current/default python version
if this helps you plz upvote, I'm new on this platform.
Try : python3.* -m venv myvenv -
And don't forget to replace * with your specific version of python
I had to mention the specific version of python and replace python3.10 with you version
$ sudo apt-get update -y && sudo apt-get upgrade -y
$ sudo apt-get install python3.10-venv
Creating a virtual environment
$ python3.10 -m venv --system-site-packages Project_Name
If your intention was to get python3.8 incl. pip and venv on Ubuntu 18.04:
sudo apt install python3.8 python3.8-venv python3-pip # there is no python3.8-pip package
python3.8 -m venv venv
source venv/bin/activate
python --version # -> python 3.8.0
pip --version # -> pip 9.0.1 from /home/user/venv/lib/python3.8/site-packages (python 3.8)
Try installing python3-distutils as well.
Altogether,
for python 3.8, the following worked for me.
$ apt-get install python3.8 python3.8-venv python3.8-distutils python3.8-dev
I just ran across this issue on several Debian/Ubuntu systems. Same error as above.
Findings
I tried to create a venv manually with:
python -m venv venvdir
This failed in the same way as others have mentioned. But it did create the shell of the venv. So I tried running ensurepip:
venvdir/bin/python -m ensurepip
Traceback (most recent call last):
File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/usr/lib/python3.9/ensurepip/__main__.py", line 5, in <module>
sys.exit(ensurepip._main())
File "/usr/lib/python3.9/ensurepip/__init__.py", line 266, in _main
return _bootstrap(
File "/usr/lib/python3.9/ensurepip/__init__.py", line 166, in _bootstrap
copy_wheels(dependencies, venv_wheel_dir, sys.path)
File "/usr/lib/python3.9/ensurepip/__init__.py", line 144, in copy_wheels
assert len(wheel_names) == 1, wheel_names
AssertionError: ['/usr/share/python-wheels/pyparsing-2.2.0-py2.py3-none-any.whl', '/usr/s
hare/python-wheels/pyparsing-2.4.7-py2.py3-none-any.whl']
This seemed odd. A quick look into /usr/share/python-wheels/ revealed - indeed - multiple versions of the same wheel as the error suggests. I have no clue why ensurepip is also ensuring that it only finds one wheel file, go figure.
Solution
A check of dpkg -S /usr/share/python-wheels indicated that the python-pip-whl package is the source of those files. This appears to be true for both Ubuntu and Debian.
So, I did:
cd /usr/share
sudo mv python-wheels python-wheels.old
sudo apt reinstall python-pip-whl
And it worked - no more errors. There are no longer duplicates in /usr/share/python-wheels
Absolutely no clue how there were duplicates or why ensurepip is so sensitive to duplicates there... Probably a package upgrade gone wrong somewhere.
I had the same problem - the python env has 2 versions for 2.7 and 3.6.
All you need to do is:
Install the latest version of pip by installing pyenv installer
Make sure you follow the steps of installing pyenv found here
Good Luck!
I had the same problem for an existing project when executing python3 -m venv venv. I had just updated my Ubuntu and Python versions. After removing the already existing venv folder the issue was solved. (I have also tried the UTF-8 solution.)
My problem were related to permissions and ownership.
I was logged in with a different user as the owner of the current directory, which led to this error.
After reviewing and fixing all permissions I was able to install the venv regularl
This worked for me...
Firstly, I ran
sudo apt-get update
Then
sudo apt-get install -y python3-venv zip
Ran into the same issue recently. None of the solutions mentioned above worked for me. I eventually get it to working by installing pip3.
apt-get install python3-pip
# then run
python3.8 -m venv env
If you came across this issue while trying to run python -m build to build a python package, this means there probabaly is a syntax issue in your setup.cfg or setup.py file that causes an error creating the temporary venv required for installing dependencies.
Using pip wheels . will give you a less misleading error message.
For Linux, it is not installed by default you have to install venv
// at first check python version
python --version
// install
sudo apt update
sudo apt install python3.8-venv
sudo apt install python3.8-distutils
// create new env
python3 -m venv project-name
source project-name/bin/activate
All of these suggestions didn't help me.
$ apt list python3 -a
python3/now 3.6.7-1~18.04 amd64 [installed,local]
python3/bionic 3.6.5-3 amd64
So I did: sudo apt-get install python3/bionic
Now I have python 3.6.5 and apt-list showed a better list:
$ apt list python3 -a
python3/bionic 3.6.5-3 amd64
With sudo apt-get install python3-venv/bionic I could install pythno3-venv and everything worked.
In my case, running sudo apt-get install python3.8-venv succeeds but it shows the same error when running python3 -m venv .venv.
Finally, this command works out without changing locale.
python3.8 -c 'import venv; venv.create(".venv", with_pip=True)'
Here is my answer for Ubuntu 14.04. I was able to make venv and pip work with various Python versions. Details:
3.4: Ubuntu 14.04 has Python 3.4 (as package python3.4 etc.). It works:
$ sudo apt-get install python3.4 python3.4-dev python3.4-venv gcc libc6-dev
$ mkdir /tmp/try3.4
$ python3.4 -m venv /tmp/try3.4
$ . /tmp/try/bin/activate
(try3.4) $ pip install print-hello-world
...
(try3.4) $ print-hello-world
Hello World!
If python3.4-venv is removed from the apt-get install command above, then python3.4 -m venv displays the same error message as in the question. However, the error message mentions apt-get install python3-venv to solve it, but that doesn't work, there is no such package. (The correct package name is python3.4-venv.)
Please note that Python 3.4 is fairly old, and some Python packages available in PyPI (via pip) don't work with it.
3.5: It can be installed from the deadsnakes repository. It works:
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.5 python3.5-dev python3.5-venv gcc libc6-dev
$ mkdir /tmp/try3.5
$ python3.5 -m venv /tmp/try
$ . /tmp/try/bin/activate
(try3.5) $ pip install print-hello-world
...
(try3.5) $ print-hello-world
Hello World!
3.6: Ditto, it can be installed from the deadsnakes repository. It works:
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.6 python3.6-dev python3.6-venv gcc libc6-dev
$ mkdir /tmp/try3.6
$ python3.6 -m venv /tmp/try3.6
$ . /tmp/try3.6/bin/activate
(try3.6) $ pip install print-hello-world
...
(try3.6) $ print-hello-world
Hello World!
3.7: It doesn't work, because pip install fails with import _ssl, and python3.7 in the deadsnakes repo doesn't have that module, because Ubuntu 14.04 ships with on old version of OpenSSL which Python 3.7 doesn't support. See more details in this bug.
3.8--: No Ubuntu 14.04 package for these Python versions in the Ubuntu or deadsnakes repositories.
In my case, the command failed because I was still in a virtual env but did not notice it very quickly.
If it is the case, try calling deactivate.
I do not have sudo rights and I have to use python3.5:
Install virtualenv: pip3 virtualenv
Create virtualenv without pip: python3 -m venv --without-pip <path>
Downloaded the proper pip bootstrap: https://bootstrap.pypa.io/pip/3.5/get-pip.py
Run: <path>/bin/python3 get-pip.py
I did 'source <path>/bin/activate' and I got a working environment.
The solution for installing python3-venv is accurate since debian/ubuntu split the python distribution across multiple packages, so you do not actually have a full python install. If you really do not want to install this apt package, here is an alternative
python3 -m pip install virtualenv
virtualenv .venv
This will create fully functioning venv.

Importing modules that work in Python 2.7 but not Python 3.4

I have previously been using PyCharm with Python 2.7, and have been able to import the module sklearn, which was intalled via sudo apt-get install python-sklearn.
However, I have now changed the settings in PyCharm to use Python 3.4. Now, it gives me the error: ImportError: No module named 'sklearn'.
I suppose this is because sklearn was installed in /usr/lib/python2.7/dist-packages. But in /usr/lib/python3.4, there is no directory called dist-packages. However, I have a directory called /usr/lib/python3/dist-packages, which has just one directory, which is dist-packages.
Any idea on what I need to do to clean this all up?
You'll need to install sklearn for Python 3.4. Ubuntu currently does not have a python3-sklearn package available, unfortunately, so you'll have to follow the installations instructions to install this yourself.
This includes installing build dependencies:
sudo apt-get install build-essential python3-dev python3-setuptools \
python3-numpy python3-scipy \
libatlas-dev libatlas3gf-base
You may have to set the right implementation (Ubuntu 13.04 and newer):
sudo update-alternatives --set libblas.so.3 \
/usr/lib/atlas-base/atlas/libblas.so.3
sudo update-alternatives --set liblapack.so.3 \
/usr/lib/atlas-base/atlas/liblapack.so.3
followed by
pip3 install --user -U scikit-learn
for a local install (your account only), or
sudo pip3 install -U scikit-learn
for a global install.

How do we install yaafe on linux?

I've been trying to install Yaafe Library on my linux system, but I'm unable to do it as I can't compile the yaafe source using ccmake. Does anyone have the detailed step-by-step procedure for the same?
I tried to follow the instructions, which failed for me during compile. The ccmake can be replace by cmake. I could not install libhdf5-serial-1.8.4, because it was integrated in the main package.
Alternative approach
An alternative to yaafe would be librosa, which has the advantage of being available via PyPi. You install it via (assuming Debian/Ubuntu)
apt-get install pip
(for the PyPi client), and
pip install librosa
if you follow their advice and install scikits.samplerate, you also need libsamplerate0-dev:
apt-get install libsamplerate0-dev
The home page of the library includes a thorough manual for compiling yaafe.
I am citing the beginning here:
$ sudo apt-get install cmake cmake-curses-gui libargtable2-0 libargtable2-dev libsndfile1 libsndfile1-dev libmpg123-0 libmpg123-dev libfftw3-3 libfftw3-dev liblapack-dev libhdf5-serial-dev libhdf5-serial-1.8.4
$ mkdir build
$ cd build
$ ccmake -DCMAKE_PREFIX_PATH=<lib-path> -DCMAKE_INSTALL_PREFIX=<install-path> ..
see the rest there.
That's what I had to do in Ubuntu 14.04 to get it working:
sudo apt-get install build-essential -y
sudo apt-get install libeigen3-dev
sudo apt-get install cmake cmake-curses-gui libargtable2-0 libargtable2-dev libsndfile1 libsndfile1-dev libmpg123-0 libmpg123-dev libfftw3-3 libfftw3-dev liblapack-dev libhdf5-serial-dev libhdf5-7
Download Yaafe from here:https://github.com/Yaafe/Yaafe/archive/master.zip
Extract Yaafe-master.zip
Inside Yaafe-master directory:
mkdir build
cd build
ccmake ..
make
sudo make install
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/
Also add this path to your IDE (Enviromental Variables) if yaafe does not work with it.
I just installed it using Anaconda, and it was extremely easy! Just install Anaconda like the link tells you to. On the last step, I recommend you allow Anaconda to modify your PATH so that when you type python on the command line, it uses the Anaconda version of Python. Then restart your terminal, just to make sure it's using the Anaconda stuff you just installed.
Then, assuming you're using Ubuntu, you just need to type the following command:
conda install --channel https://conda.anaconda.org/Yaafe yaafe

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.

Categories

Resources