Ubuntu нет такого файла или каталога python
Обновлено: 07.07.2024
Я пытаюсь создать разделяемую библиотеку, используя файл расширения C, но сначала мне нужно сгенерировать выходной файл, используя следующую команду:
utilsmodule.c: 1: 20: фатальная ошибка: Python.h: компиляция такого файла или каталога не прекращена.
Я попробовал все предложенные решения через Интернет, но проблема все еще существует. У меня нет проблем с Python.h . Мне удалось найти файл на моей машине.
Мне удалось решить эту проблему и создать файл .so в одной команде
Это означает, что Python.h отсутствует в путях включения вашего компилятора по умолчанию. Вы установили его для всей системы или локально? Какая у тебя ОС?
Вы можете использовать флаг -I<path> , чтобы указать дополнительный каталог, в котором ваш компилятор должен искать заголовки. Вероятно, вам придется использовать -L<path> , чтобы gcc мог найти библиотеку, с которой вы связываетесь, используя -l<name> .
Конечно, python-dev или libpython-all-dev - первое, что нужно сделать ( apt ) install , но если это не поможет, как в моем случае, я советую вам установить Интерфейсы внешних функций упаковывают sudo apt-get install libffi-dev и sudo pip install cffi .
Это должно помочь, особенно если вы видите ошибку как / из c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory .
В AWS API (centOS) его
Две вещи, которые вы должны сделать.
Установите пакет разработки для Python, в случае Debian / Ubuntu / Mint это делается командой:
Во-вторых, файлы включения по умолчанию не включены в путь включения, и библиотека Python не связана с исполняемым файлом по умолчанию. Вам необходимо добавить эти флаги (соответственно замените версию Python):
Другими словами, ваша команда компиляции должна быть:
Похоже, вы неправильно установили заголовочные файлы и статические библиотеки для python dev. Используйте менеджер пакетов, чтобы установить их для всей системы.
Для apt ( Ubuntu, Debian . ):
Для yum ( CentOS, RHEL . ):
Для dnf ( Fedora . ):
Для zypper ( openSUSE . ):
Для apk ( Альпийский . ):
Для apt-cyg ( Cygwin . ):
Иногда даже после установки python-dev ошибка сохраняется. Проверьте на наличие ошибки, если отсутствует «gcc».
Для apt (Ubuntu, Debian . ):
Для yum (CentOS, RHEL . ):
Для dnf (Fedora . ):
Для zypper (openSUSE . ):
Для apk (Alpine . ):
Эта ошибка произошла, когда я попытался установить ctds на CentOS 7 с Python3.6. Я сделал все трюки, упомянутые здесь, включая yum install python34-devel . Проблема в том, что Python.h был найден в /usr/include/python3.4m but not in /usr/include/python3.6m . Я пытался использовать --global-option для указания на включение dir ( pip3.6 install --global-option=build_ext --global-option="--include-dirs=/usr/include/python3.4m" ctds ). Это привело к тому, что lpython3.6m не был найден при связывании ctds.
Python.h должен быть в вашем пути включения для gcc. Какая бы версия Python ни использовалась, например, если она равна 3,6, она обычно должна быть в /usr/include/python3.6m/Python.h .
I am trying to build a shared library using a C extension file but first I have to generate the output file using the command below:
After executing the command, I get this error message:
I have tried all the suggested solutions over the internet but the problem still exists. I have no problem with Python.h . I managed to locate the file on my machine.
31 Answers 31
Looks like you haven't properly installed the header files and static libraries for python dev. Use your package manager to install them system-wide.
For apt (Ubuntu, Debian. ):
For yum (CentOS, RHEL. ):
For dnf (Fedora. ):
For zypper (openSUSE. ):
For apk (Alpine. ):
For apt-cyg (Cygwin. ):
2,154 2 2 gold badges 11 11 silver badges 30 30 bronze badges 284k 83 83 gold badges 516 516 silver badges 656 656 bronze badgesOn Ubuntu, I was running Python 3 and I had to install
If you want to use a version of Python that is not linked to python3, install the associated python3.x-dev package. For example:
5,674 1 1 gold badge 13 13 silver badges 17 17 bronze badgesFor Python 3.7 and Ubuntu in particular, I needed
sudo apt install libpython3.7-dev
. I think at some point names were changed from pythonm.n-dev to this.
for Python 3.6, 3.8, and 3.9 similarly:
sudo apt install libpython3.6-dev
sudo apt install libpython3.9-dev
4,535 4 4 gold badges 24 24 silver badges 25 25 bronze badgesTwo things you have to do.
Install development package for Python, in case of Debian/Ubuntu/Mint it's done with command:
Second thing is that include files are not by default in the include path, nor is Python library linked with executable by default. You need to add these flags (replace Python's version accordingly):
In other words your compile command ought to be:
122k 35 35 gold badges 207 207 silver badges 239 239 bronze badges do I have to add flags for each included file in the C extension file ?? If you are using another version of Python, 3.3 for example: sudo apt-get install python3.3-devon Fedora run this for Python 2:
and for Python 3:
24.4k 24 24 gold badges 97 97 silver badges 133 133 bronze badges On Mint 18.2 (Ubuntu based), it was apt-get install python-dev .If you are using tox to run tests on multiple versions of Python, you may need to install the Python dev libraries for each version of Python you are testing on.
7,598 2 2 gold badges 56 56 silver badges 53 53 bronze badgesMake sure that the Python dev files come with your OS.
You should not hard code the library and include paths. Instead, use pkg-config, which will output the correct options for your specific system:
You may add it to your gcc line:
I get the following error message on RHEL: "Unknown option -I/usr/include/python2.7" @FedorSteeman, someone edited my answer and removed the newline from the command.Solution for Cygwin
You need to install the package python2-devel or python3-devel , depending on the Python version you're using.
Example (modify setup.exe 's filename and Python's major version if you need):
You can also check my other answer for a few more options to install Cygwin's packages from the command-line.
20.3k 8 8 gold badges 73 73 silver badges 67 67 bronze badgesFor me, changing it to this worked:
I found the file /usr/include/python2.7/Python.h , and since /usr/include is already in the include path, then python2.7/Python.h should be sufficient.
You could also add the include path from command line instead - gcc -I/usr/lib/python2.7 (thanks @erm3nda).
In AWS API (centOS) its
12.1k 6 6 gold badges 52 52 silver badges 80 80 bronze badges This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. It does provide an answer. Although you have to substitute the version for what you need. this helped overcome my issues attempting to pip install cryptography on an amazon linux instance. This was a helpful answer, while it is possible to install python-devel or python2-devel on Amazon Linux, this is the only one that actually worked for me when running a pip install inside a virtualenvAWS EC2 install running python34:
sudo yum install python34-devel
If you use a virtualenv with a 3.6 python (edge right now), be sure to install the matching python 3.6 dev sudo apt-get install python3.6-dev , otherwise executing sudo python3-dev will install the python dev 3.3.3-1, which won't solve the issue.
Worked great for me on 3.5(.2), too. Explicitly installing the right dev package for your version of Python is a Good Thing.In my case, what fixed it in Ubuntu was to install the packages libpython-all-dev (or libpython3-all-dev if you use Python 3).
4,970 5 5 gold badges 28 28 silver badges 37 37 bronze badges @Oriol Nieto, Thank you very much. python-all-dev also solved the issue for me.It's not the same situation, but it also works for me and now I can use SWIG with Python3.5:
I was trying to compile:
With Python 2.7 works fine, not with my version 3.5:
existe_wrap.c:147:21: fatal error: Python.h: No existe el archivo o el directorio compilation terminated.
After run in my Ubuntu 16.04 installation:
Now I can compile without problems Python3.5:
20.3k 8 8 gold badges 73 73 silver badges 67 67 bronze badgesI managed to solve this issue and generate the .so file in one command
I also encountered this error when I was installing coolprop in ubuntu.
For ubuntu 16.04 with python 3.6
If ever this doesn't work try installing/updating gcc lib.
try apt-file. It is difficult to remember the package name where the missing file resides. It is generic and useful for any package files.
Now you can make an expert guess as to which one to choose from.
If you're using Python 3.6 on Amazon Linux (based on RHEL, but the RHEL answers given here didn't work):
You must install the Python development files on your operating system if the Python provided with your operating system does not come with them. The many answers on this question show the myriad ways this can be achieved on different systems.
When you have done so, the problem is telling the compiler where they're located and how to compile against them. Python comes with a program called python-config . For compilation, you need the --includes output and for linking a program against the Python library (embedding Python into your program) the --ldflags output. Example:
The python-config program can be named after the Python versions - on Debian, Ubuntu for example these can be named python3-config or python3.6-config .
Sure python-dev or libpython-all-dev are the first thing to ( apt ) install , but if that doesn't help as was my case, I advice you to install the foreign Function Interface packages by sudo apt-get install libffi-dev and sudo pip install cffi .
This should help out especially if you see the error as/from c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory .
Here is yet another solution, because none of these solutions worked for me. For reference, I was trying to pip install something on an Amazon Linux AMI base Docker image for Python 3.6.
NOTE: If you're getting the error when compiling C++, use CPLUS_INCLUDE_PATH .
Alternatively, you may prefer to use another Docker image. For example, I was trying to install asyncpg
=0.24.0 on python:3.9.4-slim , which generated the same error as you saw. However, when I updated the image to python:3 , it worked fine.
Worked for amazon linux like a charm. Glad i found your solution. Thank youThis error occurred when I attempted to install ctds on CentOS 7 with Python3.6. I did all the tricks mentioned here including yum install python34-devel . The problem was Python.h was found in /usr/include/python3.4m but not in /usr/include/python3.6m . I tried to use --global-option to point to include dir ( pip3.6 install --global-option=build_ext --global-option="--include-dirs=/usr/include/python3.4m" ctds ). This resulted in a lpython3.6m not found when linking ctds.
Finally what worked was fixing the development environment for Python3.6 needs to correct with the include and libs.
Python.h needs to be in your include path for gcc. Whichever version of python is used, for example if it's 3.6, then it should be in /usr/include/python3.6m/Python.h typically.
For ubuntu 20.04 you can use following package to python command. And it is python 3.
sudo apt-get install python-is-python3
Problem scenario:
If Python 3 is not installed, install it: apt-get install python3
If Python 3 has been installed, run these commands: whereis python3
Then we create a symlink to it: sudo ln -s /usr/bin/python3 /usr/bin/python
I had the same problem after installing Ubuntu 18.04 and trying to run some python scripts.
but I still got the same error. I solved it by:
You do seem to have python3 installed, but it isn't called python and anyway the script you want to run ( configure ) requires python 2. So:
If that fails again, call it with python2 explicitly:
I had the same problem, It got solved by linking python to python2.7 with the following commands
1,073 1 1 gold badge 9 9 silver badges 16 16 bronze badgesYet Another Solution:
Tested & verified on my 20.04LTS system. See man update-alternatives for details. And, "No - it's not necessary to have Python2 installed for this to work."
If you don't want to mess up with your system configuration, you can just replace the first line of your configure file
Just for reference. I had a similar issue - running a python script from the docker container failed with "No such file or directory", my solution was to force Unix style line endings on the checkout of the code and in the IDE (as it was bind-mounted from the Windows host to the container).
Check the spelling in the first line. Trailing spaces have been known to prevent the shell from locating the shell.
The training space confused bash.
110k 51 51 gold badges 301 301 silver badges 464 464 bronze badges Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.Linked
Related
Hot Network Questions
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Ubuntu and Canonical are registered trademarks of Canonical Ltd.In Ubuntu 20.04, python3 is the installed default. The python variable is not set:
We can get around this by using python3 and which :
287 1 1 gold badge 2 2 silver badges 9 9 bronze badgesI think python is missing on your system so,
First of all check if you have python installed . To check this simply open terminal and type python . If it shows python version and prompt then quit by typing quit()
And if python is missing then install it with this command :
If that does not help, then try this command:
The easiest way to deal with this in Ubuntu 20.04+ is to symlink python to python3:
sudo ln -s /usr/bin/python3 /usr/bin/python
Note, however, that if you install other Python programs that rely on the older version of Python, they may not run or work correctly until you remove the symlink and install the older version of Python, or fix the programs to use Python 3. But the older Python version is no longer supported, so it would be better to use only Python programs that can run under Python 3 in the first place.
I had the exact same problem trying to install youtube-dl in ubuntu 20.04 and spent a long time trying to resolve. On the verge of giving up, I saw this from Canonical and thought it looks too simple but tried it anyway! Problem solved!
sudo snap install youtube-dl
This works for ubuntu 20.04 LTS:
The python variable is not set and update-alternatives will not work either. Let's fix that.
Afterwards, we can decide which version python points to using $ sudo update-alternatives --config python .
Install alternatives for python 2 and 3
Change which version to use (v3 default since higher priority)
If you don't need python 2 and only need python 3, the easiest is to just
It's actually just a symlink. The package description explains it:
In Ubuntu, all python packages use explicit python3 or python2 interpreter and do not use unversioned /usr/bin/python at all. Some third-party code is now predominantly python3 based, yet may use /usr/bin/python .
This is a convenience package which ships a symlink to point the /usr/bin/python interpreter at the current default python3 . It may improve compatibility with other modern systems, whilst breaking some obsolete or 3rd-party software.
Читайте также: