programing tip

Python3 : ImportError : 모듈 다중 처리의 값을 사용할 때 '_ctypes'라는 모듈이 없습니다.

itbloger 2020. 9. 20. 09:08
반응형

Python3 : ImportError : 모듈 다중 처리의 값을 사용할 때 '_ctypes'라는 모듈이 없습니다.


Ubuntu를 사용하고 있으며 Python 2.7.5 및 3.4.0을 설치했습니다. Python 2.7.5에서는 변수를 성공적으로 할당 할 수 x = Value('i', 2)있지만 3.4.0에서는 할당 할 수 없습니다. 나는 얻고있다:

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'

3.4.0 소스를 설치하여 방금 3.3.2로 업데이트했습니다. /usr/local/lib/python3.4에 설치되었습니다 .

Python 3.4로 올바르게 업데이트 했습니까?

Python 3.4가 usr / local / lib 에 설치되어있는 반면 Python 3.3.2는 여전히 usr / lib에 설치되어 있으므로 덮어 쓰지 않았습니다.


libffi-devpython3.7을 설치 하고 다시 설치하면 문제가 해결되었습니다.

py 3.7을 깨끗하게 빌드 libffi-dev하려면 필요합니다. 그렇지 않으면 나중에 실패합니다.

RHEL / Fedora를 사용하는 경우 :

yum install libffi-devel

또는

sudo dnf install libffi-devel

Debian / Ubuntu를 사용하는 경우 :

sudo apt-get install libffi-dev

새로운 Debian 이미지에서 https://github.com/python/cpython을 복제 하고 다음을 실행합니다.

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

이제 configure위에서 복제 한 파일을 실행합니다 .

./configure
make # alternatively `make -j 4` will utilize 4 threads
sudo make altinstall

3.7을 설치하고 나를 위해 일했습니다.

약간의 업데이트

이 답변을 더 많은 설명으로 업데이트하겠다고 말한 것 같으며 2 년 후에는 추가 할 내용이 많지 않습니다.

  • 이 SO 게시물은 특정 라이브러리 python-dev가 필요한 이유를 설명 합니다.
  • 이 SO 게시물은make 명령 에서 인수 altinstall와 반대되는를 사용할 수 있는지 설명합니다 .install

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.


Detailed steps to install Python 3.7 in CentOS or any redhat linux machine:

  1. Download Python from https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
  2. Extract the content in new folder
  3. Open Terminal in the same directory
  4. 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


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.


Refer to 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".

참고URL : https://stackoverflow.com/questions/27022373/python3-importerror-no-module-named-ctypes-when-using-value-from-module-mul

반응형