Missing Python.h and impossible to find - python

I know there are already similar questions about the missing Python.h but NO solution worked for me by now.
I need Python libraries in order to use Tossim, which is a tinyOS simulator (http://tinyos.net).
Python appears to be already installed on my Ubuntu 12.04 system.
In fact whenever I run the command
$ python -V
I get the output 2.7.3
Anyway when I try to locate Python.h no file is found. Python libraries are located in usr/lib/ but no headers in the folder.
Mind that I already tried the most common solution for this problem, that is $ sudo apt-get install python-dev , and also $ sudo apt-get update.
None of them worked for me.
What should I do now? I tried to remove and reinstall python-dev, with no success. I only think to manually download and place the header into the folder usr/lib/python2.7.
But I doubt it is a good idea. Can somebody help me? Thank you in advance.`

Ubuntu (and Debian) stores Python include files in /usr/include/python2.7. If the python2.7-dev package is installed (a dependency of python-dev) then Python.h will be located at:
/usr/include/python2.7/Python.h
You can locate what packages contain the file with the command:
dpkg -S Python.h
or list what files are installed with a package with:
dpkg -L python2.7-dev

Related

Brew fails to install Python: can not symlink

I'm trying to install python 2.7 on the latest version of OSX using brew but I get the following error...
.app bundles were installed.
Run `brew linkapps` to symlink these to /Applications.
Warning: Could not link python. Unlinking...
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link python'
Possible conflicting files are:
/usr/local/bin/pip
/usr/local/bin/easy_install-2.7
/usr/local/bin/easy_install
Would anyone know how to fix this error? I tried brew link python but this did not work. I'm new to Linux/OSX, so if this is really obvious, I would still appreciate it if someone could point me in the right direction!
The error means those files already exist in /usr/local/bin
If you 'ls -lF' on that dir, are they sym links that point to a path with the word 'cellar' in it?
If so, then brew already put them in place for you. You're probably missing /usr/local/bin from your PATH
If not, then something else put them there earlier. On a fresh mac, that directory is empty. Brew is a better way to manage those files, so if it was my machine I would remove those files from /usr/local/bin, then you can run brew link. I'd probably keep them in another spot temporarily in case I later discovered a need for them.
Also, run brew doctor when you have a chance. It will tell you about any other problems like this.
Brew wants to own /usr/local/bin. I would let it, it's a great tool.
Fix for macOS Mojave 10.14.2 (2018-12)
I was able to install python with brew using these commands.
brew install python
sudo chown -R $(whoami) $(brew --prefix)/*
sudo install -d -o $(whoami) -g admin /usr/local/Frameworks
brew link python
python3 --version
The most likely answer is that you have somehow installed executables (notably pip and easy-install) that Homebrew packages with it's install of Python outside of the Homebrew workflow. Because Homebrew is not managing these executables (that is, the executables are not symlinks to the versions stored in Homebrew's Cellar repository), its default action is to not overwrite these executables. There are two options you have to resolve this:
You can remove the files that are blocking the installation. Depending on how you installed the executables previously, you might have to do this through manual rm commands. Once you do that, you can run brew link python and Homebrew will happily form the symlinks now that there are no pre-existing executables.
You can tell Homebrew you don't actually care that those executables exist, and you want to overwrite them anyways by using brew link --overwrite python as described in this answer.
In either case, be aware that both pip and easy-install will have dependency files in a site-packages folder somewhere on your computer from their original installation. It would be advisable for you to audit your Python install and your computer for extraneous site-packages folders.

pip-installed uWSGI ./python_plugin.so error

I've installed uWSGI using pip and start it up with an XML to load my application. The XML config contains <plugin>python</plugin>. On my new server it leads to an error:
open("./python_plugin.so"): No such file or directory [core/utils.c line 3321]
!!! UNABLE to load uWSGI plugin: ./python_plugin.so: cannot open shared object file: No such file or directory !!!
I can find the .c and the .o versions:
sudo find / -name 'python_plugin.c'
/srv/www/li/venv/build/uwsgi/build/uwsgi/plugins/python/python_plugin.c
/srv/www/li/venv/build/uwsgi/plugins/python/python_plugin.c
sudo find / -name 'python_plugin.o'
/srv/www/li/venv/build/uwsgi/build/uwsgi/plugins/python/python_plugin.o
/srv/www/li/venv/build/uwsgi/plugins/python/python_plugin.o
sudo find / -name 'python_plugin.so'
But no .so found. My previous system had a uwsgi install through apt-get, but that's really old (and I'm quite sure it uses the pip installed uwsgi normally, but maybe not for shared objects then?)
Some background info:
Ubuntu 12.0.4 LTS
Python 2.7 (virtualenv)
I've installed uWSGI in my venv, using the normal pip install uwsgi (no sudo)
So I'm a tad clueless :( I can't be the only person in the world to have this, right? Should I compile the .so objects myself? (If so, how?) Or is there another great solution?
Distros should package uWSGI in a modular way, with each feature as a plugin. But when you install using language specific ways (pip, gem...) the relevant language is embedded, so you do not need to load the plugin
For anyone that is having trouble with this, basically you need to remove lines that state your plugin from your configuration files if you change from a distro package to a pypi or gem install. I was previously using the Ubuntu/Debian package for uwsgi, but it was old so I upgraded to use pip instead.
So, in my configuration .ini file, I had the following line:
plugin = python
Removing that line fixes the problem.
Maybe you forgot this command
$ apt-get install uwsgi-plugin-python
If you're using Python3, try this command instead:
$ apt-get install uwsgi-plugin-python3
Install all available plugins: sudo apt-get install uwsgi-plugins-all
As of 6/2018 the yum package name was updated from uwsgi-plugin-python to uwsgi-plugin-python2 https://src.fedoraproject.org/rpms/uwsgi/pull-request/4#
The new install command is therefore yum install uwsgi-plugin-python2

Python audiolab install, unable to install (or find) libsndfile on Mac OSX

Trying to install scikits.audiolab-0.11.0 on Mac, bit it requires libsndfile: http://www.mega-nerd.com/libsndfile/. I did install libsndfile supposedly, using libsndfile_python-1.0.0-py2.7-macosx10.5.mpkg, but the audiolab setup gives an error: libsndfile library not found. The error from the audiolab installer is below. It suggests that the location of the libsndfile can be specified in the site.cfg.
My inexperience with these type of installs are getting in the way of understanding this. Can anyone offer some advice on how to get this done?, or answer my questions below?
If the libsndfile was installed, where would it be, so I can specify the location? Else how to install it properly?
What is the site.cfg file? I see a site.cfg.bdist_wininst, and a site.cfg.win32 in the scikits.audiolab-0.11.0 folder that I downloaded.
What is meant by "specified in the site.cfg file in section [sndfile]" (see error below). Does this mean that I should replace the word "sndfile" with the /path/to/libsndfile between the brackets?
By the way, I checked in my /usr/lib dir and there is no libsndfile. I take it that there is where the audiolab setup will look for the file, by default.
Thanks for reading, and any help.
Error from audiolab installer:
numpy.distutils.system_info.NotFoundError: sndfile (http://www.mega-nerd.com/libsndfile/) library not found.
Directories to search for the libraries can be specified in the
site.cfg file, in section [sndfile].
libsndfile_python sounds like a binding to libsndfile rather than libsndfile itself. You probably do not have libsndfile installed. It should, however, be quite easy to install if you already have the developer tools installed:
First, download the latest source.
Unpack it somewhere.
Open Terminal and cd to the directory you unpacked.
Configure it: ./configure
Build it: make -j8
Install it (requires administrative rights): sudo make -j8 install
You can then delete the directory you unpacked, but you may want to keep it for easy uninstallation.
To install libdsnd in a mac (Tested in a Yosemite 10.10.3):
1- Install Homebrew (paste this on a terminal):
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2- Install libsnd:
brew install libsndfile
3- Link libsnd:
brew link --overwrite libsndfile
4- Install scikits.audiolab:
sudo easy_install scikits.audiolab
There you go!
For windows users:
Download file :
"scikits.audiolab‑0.11.0‑cp27‑cp27m‑win32.whl"
from "https://www.lfd.uci.edu/~gohlke/pythonlibs/#scikits.audiolab"
Install it using command : pip install scikits.audiolab‑0.11.0‑cp27‑cp27m‑win32.whl
install libsndfile from http://www.mega-nerd.com/libsndfile/ using setup:
http://www.mega-nerd.com/libsndfile/files/libsndfile-1.0.28-w32-setup.exe
copy "libsndfile-1.dll" from C:\Program Files (x86)\Mega-Nerd\libsndfile\bin
to folder Lib\site-packages\scikits\audiolab folder within your Python installation folder,
ex: C:\Python2711\Lib\site-packages\scikits\audiolab
For me this solved a problem.
Credits to "https://github.com/cournape/audiolab/issues/7" - "samuelgarcia"

python-dev installation error: ImportError: No module named apt_pkg

I am Debian user, and I want to install python-dev, but when I run the code in the shell as a root:
# aptitude install python-dev
I get the following error:
Traceback (most recent call last):
File "/usr/bin/apt-listchanges", line 28, in <module>
import apt_pkg
ImportError: No module named apt_pkg
What seems to be the problem and how can I resolve it?
I met this problem when doing sudo apt-get update. My env is debian8, with python2.7 + 3.4(default) + 3.5.
The following code will only re-create a apt_pkg....so file for python 3.5
sudo apt-get install python3-apt --reinstall
The following code solved my problem,
cd /usr/lib/python3/dist-packages
Locate the appropriate .so file for the python version installed on your system:
ls -l | grep apt_pkg
Create a symbolic link:
sudo ln -s apt_pkg.cpython-{your-version-number}-x86_64-linux-gnu.so apt_pkg.so
Replace {your-version-number} appropriately.
CAUTION, the following will create a symlink from apt_pkg37m to apt_pkg36m. make sure you are linking to the correct, or at least to an existing version by ls apt_pkg.cpython-*, and see which one(s) you have installed.
sudo ln -s apt_pkg.cpython-{36m,37m}-x86_64-linux-gnu.so
So, obviously, python3-apt checks the highest python version, instead of the current python version in use.
To understand why this is happening, see this answer further down: https://stackoverflow.com/a/64241654/21539
Solve it by this:
cd /usr/lib/python3/dist-packages
cp apt_pkg.cpython-34m-i386-linux-gnu.so apt_pkg.so
Or:
cd /usr/lib/python3/dist-packages
cp apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.so
Basically, if you get a No such file or directory just ls to try to get the right name.
This happened to me on Ubuntu 18.04.2 after I tried to install Python3.7 from the deadsnakes repo.
Solution was this
1) cd /usr/lib/python3/dist-packages/
2) sudo ln -s apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so
Make sure you have a working python-apt package. You could try and remove and install that package again to fix the problem with apt_pkg.so not being located.
apt-get install python-apt
This error will often occur when a newer version of python has been installed alongside an older version e.g;
Ubuntu 18.04.1 ships with python version 3.6.6
Installed ppa:deadsnakes/python3.7.1 or alternative
Run a command that uses the apt_pkg module and get an error such as;
from CommandNotFound.db.db import SqliteDatabase
File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in <module>
import apt_pkg
When we install a non-distro python3 version with apt it will set a shared module directory to be that of python3 most usually it will be /usr/lib/python3.
Most of the time this will be ok, but under some circumstances the different versions of python rely on different libraries or shared objects/libraries than the other python version does, so as other answers have pointed out we need to link the .SO to the correct python version. So if we have python3.6 installed on a 64bit system then the apt_pkg .SO link would be
sudo ln -s apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so
But the problem lies in the fact that when we install a newer python version the link will update to point to the newest python version, which leads to the error of apt_pkg module not being found.
By checking which version of python ships with your distro you can create the link as shown above.
Or we use a method to offer the command a choice of python versions to link the .SO such as;
sudo ln -s apt_pkg.cpython-{36m,35m,34m}-x86_64-linux-gnu.so apt_pkg.so
Because python will create this link to the newest installed python version we give the command the option to choose from 3 python versions, of which it will choose the highest version given.
This worked for me on after updating python3.7 on ubuntu18.04
cd /usr/lib/python3/dist-packages
sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so
I see everyone saying how to fix it with strange copying etc, but no one really said why the problem occurs.
So let me explain, for those of you who like me don't want to mess with system files only because someone on SO told them so.
The problem is that:
many system scripts have python3 shebang hardcoded into them. You can check it yourself:
~$ grep -R "\#\!/usr/bin/python3" /usr/lib/*
/usr/lib/cnf-update-db:#!/usr/bin/python3
/usr/lib/command-not-found:#!/usr/bin/python3
/usr/lib/cups/filter/pstotiff:#!/usr/bin/python3
/usr/lib/cups/filter/rastertosag-gdi:#!/usr/bin/python3 -u
grep: /usr/lib/cups/backend/cups-brf: Permission denied
/usr/lib/cups/backend/hpfax:#!/usr/bin/python3
/usr/lib/language-selector/ls-dbus-backend:#!/usr/bin/python3
/usr/lib/python3/dist-packages/language_support_pkgs.py:#!/usr/bin/python3
/usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py:#!/usr/bin/python3
/usr/lib/python3/dist-packages/cupshelpers/installdriver.py:#!/usr/bin/python3
/usr/lib/python3/dist-packages/cupshelpers/openprinting.py:#!/usr/bin/python3
/usr/lib/python3/dist-packages/cupshelpers/xmldriverprefs.py:#!/usr/bin/python3
/usr/lib/python3/dist-packages/cupshelpers/smburi.py:#!/usr/bin/python3
/usr/lib/python3/dist-packages/cupshelpers/ppds.py:#!/usr/bin/python3
/usr/lib/python3/dist-packages/cupshelpers/debug.py:#!/usr/bin/python3
/usr/lib/python3/dist-packages/DistUpgrade/dist-upgrade.py:#!/usr/bin/python3
/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py:#!/usr/bin/python3
/usr/lib/python3/dist-packages/CommandNotFound/db/db.py:#!/usr/bin/python3
/usr/lib/python3/dist-packages/Quirks/quirkreader.py:#!/usr/bin/python3
grep: /usr/lib/ssl/private: Permission denied
/usr/lib/system-service/system-service-d:#!/usr/bin/python3
/usr/lib/ubuntu-release-upgrader/check-new-release-gtk:#!/usr/bin/python3
/usr/lib/ubuntu-release-upgrader/do-partial-upgrade:#!/usr/bin/python3
/usr/lib/ubuntu-release-upgrader/check-new-release:#!/usr/bin/python3
/usr/lib/update-notifier/package-data-downloader:#!/usr/bin/python3
/usr/lib/update-notifier/backend_helper.py:#!/usr/bin/python3
/usr/lib/update-notifier/apt_check.py:#!/usr/bin/python3
/usr/lib/update-notifier/apt-check:#!/usr/bin/python3
python apt package python-apt/python3-apt is a system package, so it's for default system python
Thus, the scripts will always get the version currently linked to python3, but fail because the apt package is not present.
General solution: NEVER change default python3 link. Ever. This also applies to python link - if an app was written in Python2 with some old syntax elements that don't work in Python3, the app will not work.
[My terminal broke that way because I use Terminator, which is apparently written in Python2.7 not compatible with Python3.]
Solutions presented here either suggest copying/linking the apt package files or changing python3 link.
Let's analyse both:
Copying/linking the apt package
This shouldn't be a problem because from around Python3.4 all python scripts work on newer versions as well.
So far. But it may break in the future - if you keep your system long enough.
Changing python3 link back
This is a great solution because we can get back to "never ever changing the link"
"But I like having to type just python!" - I like it too! That's how I got to this problem in the first place!
In general, you should avoid manually changing system links - use update-alternatives instead to link different versions. This applies to any app with many versions. This will still break those system scripts (because it does change the link), but you can switch back and forth easily, without worrying whether you put link and dest in the right order or made a typo.
Consider using other name than python/python3 for your link or alias.
Or add your own python/python3 link to PATH (just like virtual environments do), without changing system links.
The solution of #user8178061 worked well but I did it with some modifications for my version wich is python3.7 with Ubuntu
I replaced the apt_pkg.cpython-3m-i386-linux-gnu.so with apt_pkg.cpython-36m-x86_64-linux-gnu.so
Here the two commands to execute:
cd /usr/lib/python3/dist-packages
sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so
Check your default Python 3 version:
python3 --version
Python 3.7.5
cd into /usr/lib/python3/dist-packages and check the apt_pkg.* files. You will find that there is none for your default Python version:
ll apt_pkg.*
apt_pkg.cpython-36m-x86_64-linux-gnu.so
Create the symlink:
sudo ln -s apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.cpython-37m-x86_64-linux-gnu.so
if you're using python 3.7 downgrade it to python 3.6 by updating Alternatives, This worked for me
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --config python3
For some reason my install was missing apt_pkg.so in the python3 dist-packages dir. (apt_pkg.cpython-33m-x86_64-linux-gnu.so was there?!) but and I had to make a symlink apt_pkg.so -> apt_pkg.cpython-33m-x86_64-linux-gnu.so
in /usr/lib/python3/dist-packages
I'm not sure whether my upgrade was broken or why this was the case. It occured after trying to upgrade (precise->raring->quantal upgrade)
A last resort is sudo cp /usr/lib/python3/dist-packages/apt_pkg.cpython-35m-x86_64-linux-gnu.so /usr/lib/python3/dist-packages/apt_pkg.cpython-36m-x86_64-linux-gnu.so
if the ln command is too much for you or somehow magically doesn't work.
cp above can also be mv if you are only dedicated to using one Python version.
I'm on Ubuntu 16.04, and upgraded to Python 3.7. Here is the error that I had when trying to add a PPA
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 11, in <module>
from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 27, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
I was able to fix this error by making symbolic link with my initial python 3.4 apt_pkg.cpython-34m-x86_64-linux-gnu.so by creating the following symbolic link
sudo ln -s apt_pkg.cpython-34m-x86_64-linux-gnu.so apt_pkg.so
In my case I ran below command and it fixed the error:
sudo apt install --reinstall python3 python python3-minimal --fix-broken
If you're using python 3.5, downgrade to 3.4. That's the safest move to do.
Under /usr/lib/python3/dist-packages you'll see *34m* which python 3.5 can't use. zhazha answer symlink to it.
In addition to making a symbolic link for apt_pkg.so, you may want to make apt_inst.so in the same manner of apt_pkg.so.
ln -s apt_inst.cpython-35m-x86_64-linux-gnu.so apt_inst.so
I tried to create the link but many other problems happened. So, you can select the old version of python to install things using:
sudo update-alternatives --config python3
And return to the desirable version right after using the same command.
Hope it works.
Windows 10 WSL v1 (Ubuntu 16.04.6 LTS)
This reddit answer (slightly modified worked for me)
sudo ln -sfn /usr/lib/python3/dist-packages/apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.so
After spending 4 hours I have got this solution which finally worked for me I hope this will help...
It is important to understand that sometimes when you upgrade from an older python version some packages stay in the previous version path, so here is what I did:
cd /usr/lib/python3/dist-packages
Check the existence of a file named apt_pkg.cpython-35m-x86_64-linux-gnu.so or 34m or 36m listing the files and when you find it, delete the current apt_pkg.so file in
/usr/lib/python3/dist-packages
Finally create a link with the correct path using apt_pkg.so like this:
cd /usr/lib/python3/dist-packages
sudo ln -s apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.so
Now you can try again and It should work.
This variant work for me.
cd /usr/lib/python3/dist-packages
ls -la /usr/lib/python3/dist-packages
sudo cp apt_pkg.cpython-38-x86_64-linux-gnu.so apt_pkg.so
If you get an error message saying too many levels of symbolic links as shown below:
cp: failed to access '/usr/lib/python3/dist-packages/apt_pkg.so': Too many levels of symbolic links
Then you need to simply unlink the apt_pkg.so file. Use the following command:
sudo unlink apt_pkg.so
And then use the command
sudo cp apt_pkg.cpython-38-x86_64-linux-gnu.so apt_pkg.so
Good luck!
Original answer: https://askubuntu.com/a/1227625
None of the answers worked for me (I am using Ubuntu 16.04 and Python 3.6). So I finally solved the issue as following:
1- connect to the FTP of the server
2- go to the folder "/usr/lib/python3/dist-packages/"
3- duplicate the file "apt_pkg.cpython-35m-x86_64-linux-gnu.so"
4- rename this duplicated file to "apt_pkg.cpython-36m-x86_64-linux-gnu.so"
That's it!
Well, the cleanest solution for me is to rebuild the related library with your new Python version, in its specific space.
I'm doing this right now, switching from Python3.9 to Python3.10.1.
So:
cd /tmp/
apt source python3-apt
cd python-apt-version-ecc
python3-new-version setup.py build
python3-new-version setup.py install
Done this also with dependencies packages (software-properties, python-launchpadlib, and so on), and now add-apt-repository works like a charm.
Which ones to recompile? Simply watch out the complains of running add-apt-repository.
By the way, I'm on Ubuntu 21.04, but the logic is the same on any Debian like system.
Please review the following documentation.
It could help you to solve the problem.
Solve the problem of replacing the python version with ModuleNotFoundError: No module named 'apt_pkg'
Please try to fix this by setting the locale variables:
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
Just in case it helps another, I finally solved this problem, that was apparently caused by python version conflicts, by redirecting the link python3, then redirecting it to the right python version:
sudo rm /usr/bin/python3
sudo ln -s /usr/bin/python3.4
You may need to enter the correct python version, found with:
python3 -V

python-config missing

I'm installing a program that requires I have python-config installed. The only problem is that I do not currently have python-config, and I cannot seem to figure out how to get it.
After searching around, I can supposedly install it via:
yum install python-devel
However, after doing so, python-config still does not exist.
I am currently using Python 2.4 on a cluster running CentOS 5.2.
Any help would be greatly appreciated!
I had the same issue running CentOS 8 with python 3.6. python3-config is installed and not python-config. you can either create a symlink or just use python3-config .
Run: pip install python-config
It would be installed and added to PATH.
Maybe it installed the file somewhere else.
First do:
which python
on command line to find where the executable file is located.
Second:
Compare the installation file folder to see if it is in the same place.
Third:
if not you can either move it to the same folder or use the executable pointed by your file by calling it from the top of your scripts.
It should look something like this:
#!/usr/bin/Python-2.7.11
Resist changing the python version of your cluster, calling it from your script with a locally installed version seems to be the best solution.
d/l from http://www.red-dove.com/config-0.3.9.tar.gz
or from http://www.red-dove.com/config-0.3.9.win32.exe
unpack and use setup.py
Jason's reply may solve your missing dependency issue though more information is required regarding how you are installing your main package which needs python-config as its dependency.
If installation is done via yum or directly from rpm files and rpm package has python-config as its dependency then even if you install python config from setup.py file missing package error wouldn't go away. In this case you may have to do force install using yum or rpm or install main application via different method.
Regards,
yum install python-configparser
FYI, if you install python3 via IUS, the equivalent python-config is /usr/lib64/python3.6/configparser.py. You may need to create a symlink by yourself.

Categories