Module Not Found Error: No module named '_ctypes' - fedora

I try to launch a python file but it returns me the error:
File "/usr/local/lib/python3.10/ctypes/init.py", line 8, in
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
The only solution I found on the web is to:
sudo dnf install libffi-dev
I tried but it doesn't work either, although it seems to work for everyone.
If anyone has a lead...

You need to reinstall python:
pyenv uninstall <your_version>
sudo apt install libffi-dev
pyenv install <your_version>
pyenv global <your_version>
I had the same error and it helped.

Related

Fresh python 3.7 / django 2.2.1 installation not recognising that mysqlclient is installed

I have a brand new django 2.2.1 project I have just installed into a python 3.7 virtualenv on OS X (10.14.4). After some frustrations I got mysqlclient to install but when I run the django dev server it doesn't recognise that it is installed:
Here are the steps I've taken so far:
brew install mysql
pipenv --three
pipenv install django==2.2.1
pipenv install mysqlclient
brew uninstall mysql
brew install mysql-connector-c
pipenv install mysqlclient
brew unlink mysql-connector-c
brew install mysql
django-admin startproject projectname
Now, the only change I have made to the out-of-the-box django installation is to change the default database backend to django.db.backends.mysql and when I run the django server I get the following:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
However, going back to the virtualenv and doing "pip install mysqlclient" gives:
Requirement already satisfied: mysqlclient in /Users/<username>/.local/share/virtualenvs/<projectname>-KrUE_JNo/lib/python3.7/site-packages (1.4.2.post1)
Any ideas why django can't see the mysqlclient installed in the virtualenv? I can confirm that all of the above has been run in the virtualenv. I suspect it has something to do with the faff that OSX makes you go through to install it but I'm not sure how to pick it apart.
I have also tried to replace mysqldb with pymysql as suggested here but that causes the server to give a different error:
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
Mysql is a given for this project so use of an alternative backend is not an option. Any help very gratefully received, many thanks in advance.
UPDATE: Output of pip freeze:
Django==2.2.1
django-auth-ldap==1.7.0
Markdown==3.1
mysql-connector-python==8.0.16
mysqlclient==1.4.2.post1
protobuf==3.7.1
pyasn1==0.4.5
pyasn1-modules==0.2.5
PyMySQL==0.9.3
pyodbc==4.0.26
python-ldap==3.2.0
pytz==2019.1
simplejson==3.16.0
six==1.12.0
sqlparse==0.3.0
xmltodict==0.12.0
UPDATE 2:
Following conor's post (thanks conor) I started again with a fresh virtualenv and again successfully installed mysqlclient1.4.2.post1. Here's the output from pip freeze now:
Django==2.2.1
mysqlclient==1.4.2.post1
pytz==2019.1
sqlparse==0.3.0
Still getting the same error when I do python manage.py runserver though:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
UPDATE 3:
Thought I would try importing the MySQLdb module on the python command line to see if I can get any more insight and it returns the following:
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/<username>/.local/share/virtualenvs/<projectname>-KrUE_JNo/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: dlopen(/Users/<username>/.local/share/virtualenvs/<projectname>-KrUE_JNo/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so, 2): Symbol not found: _mysql_affected_rows
Referenced from: /Users/<username>/.local/share/virtualenvs/<projectname>-KrUE_JNo/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so
Expected in: flat namespace
in /Users/<username>/.local/share/virtualenvs/<projectname>-KrUE_JNo/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so
SOLVED
So it looks like the issue was that on initial installation the mysqlclient library had compiled against the wrong version of mysql (not sure how that happened), so I had to force it to recompile.
Here are the steps:
brew uninstall mysql
brew uninstall myysql-connector-c
pipenv uninstall mysqlclient
brew install mysql-connector-c
At this point we need to update /usr/local/bin/mysql_config as per the instructions that conor linked to (thanks again conor), i.e. change the line that read
libs="$libs -l "
to
libs="$libs -lmysqlclient -lssl -lcrypto "
Then, to fix the resultant "library not found for -lssl" error I used the answer from this question:
export PATH="/usr/local/opt/openssl/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
Then finally force mysqlclient to recompile and reinstall mysql:
pip install --force-reinstall --ignore-installed --no-binary :all: mysqlclient
brew unlink mysql-connector-c
brew install mysql
Thanks to everyone who took time to help out!
If you're on macos do this
$ brew uninstall mysql
$ brew install mysql-connector-c
$ brew unlink mysql-connector-c
$ brew install mysql
$ pip install mysql-python
and follow the instructions here: https://pypi.org/project/mysqlclient/
Downgrading from python 3.7.4 to python 3.6 solved the issue for me on windows 10.

How to install/import pygame in virtual environment on raspberry pi running on raspbian os? [duplicate]

I'm trying to install pygame on my mac, when I import pygame, below error returned
Traceback (most recent call last): File "<pyshell#0>", line 1,
in <module> import pygame File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95,
in <module> from pygame.base import * ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found.
Did find: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper.
I have seen it is a architecture problem, however I'm not aware of how to install 32bit python.
Thanks in advance
EDIT: I realized that these steps were originally intended for python3. It should still work for python2, but I can't confirm, it's just the best answer I have.
Assuming you are using the newest macOS, here are the steps I used to install pygame. Try and uninstall what you installed for pygame previously, I'm not sure how this could affect it. This will also install the IDLE program, a python IDE developed by python, if you don't already have it.
If you have an older mac, click the source link at the bottom, which we provide instructions for older macs, which would involve downloading programs like xcode.
Install homebrew. Go into terminal and paste
ruby -e "$(curl -fsSL https<nolink>://raw.githubusercontent.com/Homebrew/install/master/install)"
then hit enter.
Paste the following into terminal, hitting enter after each line:
brew install python (brew install python3 for python3 users)
brew install mercurial
brew install sdl sdl_image sdl_mixer sdl_ttf portmidi
brew tap homebrew/headonly (if you have any trouble here, try brew install --HEAD smpeg instead)
brew install smpeg
sudo -H pip install hg+http<nolink>://bitbucket.org/pygame/pygame (You will have to enter your password, and you must be an admin. Python3 users should use sudo -H pip3 install hg+http<nolink>://bitbucket.org/pygame/pygame)
Source (although some info was updated)
For me actually, in 03/2020 with the latest OS / Python etc. I used all commands except for the last one which did not work. I simply run this and SUCCESS(!):
pip3 install pygame
I had to use these instructions in order for it to work on MAC OS 10.14.4 with Python 3.8 on date 6/2/20, assuming you already have Python installed.
brew install mercurial
brew install sdl sdl_image sdl_mixer sdl_ttf portmidi
brew install smpeg
pip install https://github.com/pygame/pygame/archive/1.9.4.zip

How to link mysql-client installed from Homebrew with diesel-cli?

I have been trying to install the Rust Diesel CLI tool using cargo install diesel_cli, but the installation fails with a linking error
ld: library not found for -lmysqlclient
clang: error: linker command failed with exit code 1
(use -v to see invocation)
I installed the MySQL client using Homebrew: brew install mysql-client. During installation I got the following warning:
mysql-client is keg-only, which means it was not symlinked into /usr/local,
because conflicts with mysql.
If you need to have mysql-client first in your PATH run:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
For compilers to find mysql-client you may need to set:
export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
export CPPFLAGS="-I/usr/local/opt/mysql-client/includeā€¯
I set the PATH and flags as in that warning message, but I still get the above linking error when trying to install the diesel-cli tool. I am unfamiliar with how to do linking in Rust - are there extra steps I need to do here to link mysqlclient directly?
Cargo ignores LDFLAGS and CPPFLAGS, you should set RUSTFLAGS instead. Something like this untested invocation:
RUSTFLAGS="-L/your_lib -I/your_include" cargo install diesel_cli
Relevant documentation.
On my side, I did not make it work with a mysql-client only. I had to install mysql with
brew install mysql
In the end, what matters is that you have a version of the mysqlclient dynamic lib.
Mines where installed here :
/usr/local/lib/libmysqlclient.21.dylib
/usr/local/Cellar/mysql/8.0.15/lib/libmysqlclient.21.dylib
And it worked.

mysql_config not found with mysql-community on CentOS 7

I need to install mysqlclient module for python3.6 on my CentOS server via pip.
The instalation breaks with following error: OSError: mysql_config not found.
I've found a solution, to install mysql-devel package, but unfortunately it breaks with following error:
Error: mariadb101u-config conflicts with mysql-community-server-8.0.4-0.1.rc.el7.x86_64
Error: mariadb101u-libs conflicts with mysql-community-libs-8.0.4-0.1.rc.el7.x86_64
Error: mariadb101u-libs conflicts with mysql-community-libs-compat-8.0.4-0.1.rc.el7.x86_64
Error: mariadb101u-common conflicts with mysql-community-common-8.0.4-0.1.rc.el7.x86_64
I cannot remove the mysql-community packages, because the server is running MySQL database based on that.
Is there any way to fix it without removing conflicting packets?
Ok, found an answer:
yum install mariadb-devel gcc python36u-devel
Solution by #Djent worked for me.
But I kept on receiving time out error while installing through yum. If you are having the same problem. You can manually download the package and install it!
On CentOS
wget https://archive.mariadb.org/mariadb-10.1.39/yum/centos7-amd64/rpms/MariaDB-10.1.38-centos73-x86_64-devel.rpm
rpm -i MariaDB-10.1.38-centos73-x86_64-devel.rpm
For other linux OS, you can find mariadb-devel at https://pkgs.org/download/mariadb-devel
First run the command (take note of python version):
sudo yum install python36-devel
Then install mysqlclient using pip.

Install / Update mysql-connector for Python

I have had no success at installing the MySQL Python connector on ubuntu 14.04. it appears that the production environment has version 1.1.6 installed. I have tried removing it with both pip and apt-get. I have attempted to update it also and have had no luck.
The command below does not work, I have tried with both "mysql-connector" and "mysql-connector-python"
pip install --user --allow-external mysql-connector-python mysql-connector-python
`
Downloading/unpacking mysql-connector-python Could not find any
downloads that satisfy the requirement mysql-connector-python Cleaning
up... No distributions at all found for mysql-connector-python
Storing debug log for failure in /root/.pip/pip.log`
If I run the command above, with just mysql-connector, it fails with an error about external managment.
"error: option --single-version-externally-managed not recognized"
I have also tried to manually remove it from "/usr/lib/python2.7/dist-packages/mysql_connector_python-1.1.6.egg-info" and that seems to have made no difference.
I have also downloaded the .deb from MySQL:
"mysql-connector-python-cext_2.1.3-1ubuntu14.04_amd64.deb" and used dpkg to install it, but that fails, as well as update fails.
Any advice?