ImportError importing ssl in MinGW-W64 Python 3.6 - python

I've used MSYS2 to install the MinGW-W64 version of Python 3.6 (mingw-w64-x86_64-python3). Upon importing ssl, an ImportError is raised:
$ python3
Python 3.6.2 (default, Aug 15 2017, 10:59:43) [GCC 7.1.0 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "G:/msys64/mingw64/lib/python3.6\ssl.py", line 101, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: DLL load failed: The specified procedure could not be found.
>>>
I'm not sure why this. pacman shows both mingw-w64-x86_64-openssl and openssl as installed. /mingw64/lib/python3.6/lib-dynload/_ssl-cpython-36m.dll exists. Other .dll files from the same directory (like those used for the json and sqlite3 modules) import fine.
To make matters weirder, the Python 2 version (mingw-w64-x86_64-python2) doesn't have this problem.

This is not a correct solution (the MSYS2 folks are working on the real solution), but as a temporary workaround for anyone else who gets stuck on this:
After installing mingw-w64-x86_64-python3 copy
C:\msys64\mingw64\bin\LIBEAY32.dll and
C:\msys64\mingw64\bin\SSLEAY32.dll
to
C:\msys64\mingw64\lib\python3.6\lib-dynload\LIBEAY32.dll and
C:\msys64\mingw64\lib\python3.6\lib-dynload\SSLEAY32.dll respectively.
Afterwards import ssl (and tools that rely on it, like pip3) should work correctly.

Related

Python 3.11 installation: some modules are missing

I'll try to be as clear and specific as possible because I've seen so many people with the same problem, but none of the answers they had worked for me.
The problem in question is: missing modules when trying to import other modules, that (by far as I understand) are installed by default in Python 3.11. eg: missing _sqlite3 when importing sqlite3.
Python 3.11.0 (main, Jan 12 2023, 03:19:52) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user_name/opt/Python-3.11.0/lib/python3.11/sqlite3/__init__.py",
line 57, in <module> from sqlite3.dbapi2 import *
File "/home/user_name/opt/Python-3.11.0/lib/python3.11/sqlite3/dbapi2.py",
line 27, in <module> from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
Context
I'm currently working on a Dreamhost VPS, running on Ubuntu 20.04.5. Since it's a Dreamhost VPS keep in mind I can't uso sudo.
I've Python 3.8 installed globally, but I'm trying to set Python 3.11 with venv. The steps to install Python 3.11 were, as indicated by 'Installing a custom version of Python 3 by Dreamhost':
cd /home/user_name/opt
wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz
tar zxvf Python-3.11.0.tgz
cd Python-3.11.0
./configure --prefix=$HOME/opt/Python-3.11.0
make
make install
When running the make command I saw the following message:
The necessary bits to build these optional modules were not found:
_bz2 _curses _curses_panel
_lzma _tkinter _uuid
readline
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
The following modules found by detect_modules() in setup.py have not
been built, they are *disabled* by configure:
_sqlite3
This is my detect_modules() in setup.py:
def detect_modules(self):
# remove dummy extension
self.extensions = []
# Some C extensions are built by entries in Modules/Setup.bootstrap.
# These are extensions are required to bootstrap the interpreter or
# build process.
self.detect_simple_extensions()
self.detect_test_extensions()
self.detect_readline_curses()
self.detect_crypt()
self.detect_openssl_hashlib()
self.detect_hash_builtins()
self.detect_dbm_gdbm()
self.detect_sqlite()
self.detect_platform_specific_exts()
self.detect_nis()
self.detect_compress_exts()
self.detect_expat_elementtree()
self.detect_multibytecodecs()
self.detect_decimal()
self.detect_ctypes()
self.detect_multiprocessing()
self.detect_tkinter()
self.detect_uuid()
# Uncomment the next line if you want to play with xxmodule.c
# self.add(Extension('xx', ['xxmodule.c']))
self.addext(Extension('xxlimited', ['xxlimited.c']))
self.addext(Extension('xxlimited_35', ['xxlimited_35.c']))
So after running the commands I just mentioned, I proceeded to setup the virtualenv to test Python 3.11:
cd /home/user_name/opt
/home/user_name/opt/Python-3.11.0/bin/python3 -m venv venv
source venv/bin/activate
And then I got the ModuleNotFoundError I mentioned at the start of the question.
Things I tried/saw:
When I checked my Python 3.11 directory, I saw that in /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload the cpython files for the modules I don't have are just not there, e.g: /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload/_sqlite3.cpython-311-x86_64-linux-gnu.so* where as in my Python 3.8, they're indeed there: /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so
I tried copying the cpython file from my 3.8 to my 3.11 and renaming it:
cp /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload
mv /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload/_sqlite3.cpython-311-x86_64-linux-gnu.so
Then when I ran Python 3.11 I got the following error:
Python 3.11.0 (main, Jan 12 2023, 04:33:33) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import _sqlite3 # this works just fine
>>> import sqlite3 # throws error
356306 segmentation fault (core dumped) python
Tried recompiling Python and running ./configure --prefix=$HOME/opt/Python-3.11.0 --enable-loadable-sqlite-extensions and didn't work.
Hope I was clear enough and thanks in advance.

'import pyPDF2' results in 'ModuleNotFoundError'

Summary of problem:
Using the python interpreter, I type import pyPDF2 and get a ModuleNotFound error even though I have installed the pyPDF2 module:
>>> import pyPDF2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyPDF2'
What I have tried:
I am using Windows 10. I am new to python. I have installed Python 3.8.3 to a C:\Python38 folder. I have installed pyPDF2 via 'pip install pyPDF2'. The windows path includes the folders: C:\Python38\Scripts\;C:\Python38\.
At the windows Command Prompt I type 'python' and get:
c:\>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
At the python interpreter prompt I type 'import pyPDF2' and get:
>>> import pyPDF2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyPDF2'
>>>
Note: There is installed an old version of python 2.7 from an ArcGIS install. Could that be causing a conflict? If not, I would rather not uninstall that version since it goes with ArcGIS, which I use.
What I am really trying to do is to automate the concatenation of 7,696 pdf files into 104 pdf files. So far my program looks like this:
import os
from pyPDF2 import PdfFileMerger
source_dir = os.getcwd()
merger = PdfFileMerger()
for item in os.listdir(source_dir):
if item.beginswith('District001_Pg'):
merger.append(item)
merger.write('District001.pdf')
merger.close()
Any help anyone is able to provide will be greatly appreciated!
If you want to run 2 different versions of python in the same machine without having conflicts, you can use VirtualEnv. Here is a document which I found on the web to get you started.
https://www.freecodecamp.org/news/installing-multiple-python-versions-on-windows-using-virtualenv/

Python 3.7 import requests returns "Chardet" error

When importing requests in python3, I'm getting the following error:
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32
bit (Intel)] on win32 Type "help", "copyright", "credits" or
"license" for more information
>>>> import requests
Traceback (most recent call last): File "<stdin>", line 1, in <module> File
"C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests-2.19.1-py3.7.egg\requests\__init__.py", line 44, in <module>
import chardet
ModuleNotFoundError: No module named 'chardet'
This is a fresh install, but because of the env I'm working in, I couldn't use pip to install requests. I had to download the source and install via the setup.py install file.
Doing some searches yields some results, but nothing that seems to be a solution for my situation.
Thanks
It is a dependency and is missing from you site-packages. Since you said you can't use pip you have to install the dependencies manually.
requires = [
'chardet>=3.0.2,<3.1.0',
'idna>=2.5,<2.8',
'urllib3>=1.21.1,<1.24',
'certifi>=2017.4.17'
]
this is what requests setup files mentioned as requirements for requests. Try installing all of these and try again.
hope this helps!
Try installing chardet module using this command:
pip3 install chardet

Importing wxPython fails in Maya

When I try to import wxPython from Maya (or mayapy), I get an import error:
[/c] ==> mayapy
Python 2.6.4 (r264:75706, May 19 2011, 13:53:43) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Program Files\Autodesk\Maya2013\Python\lib\site-packages\wx-3.0-msw\wx\__init__.py", line 45, in <module>
from wx._core import *
File "c:\Program Files\Autodesk\Maya2013\Python\lib\site-packages\wx-3.0-msw\wx\_core.py", line 4, in <module>
import _core_
ImportError: DLL load failed: The specified module could not be found.
Question:
How do I make wxPython work with Maya's Python installation?
Context:
I use PyQt, PySide and Tkinter for my UI development with Maya Python. I want to use wxPython just to try it out. I installed the version of wxPython that was meant for Python 2.6/Win64. It is installed in Maya's Python folder: C:\Program Files\Autodesk\Maya2013\Python\lib\site-packages\
I tried installing wx for a standard installation of Python 2.6 and it works fine. That is the reason I am posting this question; I am looking for a solution for why this is happening only for the Maya Python installation and not the other standard Python installation that I have.
I am using:
Maya version: 2013
Maya Python version: 2.6.4
OS: Windows 7, 64-bit.
Thank you for any help or suggestions you can give.
There are a couple of reasons you could be getting that message. Some have reported that this happens if you install a 64-bit wxPython to a 32-bit Python (or vice-versa), although I personally don't know how you could do that. That is something to check though as if you have a 64-bit vs 32-bit mismatch, you will definitely have issues.
The other more likely issue is that you need to install a Microsoft redistributable so that you have the correct DLL that wxPython needs.
"import wx" fails after installation of wxPython on Windows XP
wxPython Import Error: DLL load failed

How to install libgit2/pygit2 into virtualenv? (Ubuntu)

I have tried dulwich, and GitPython - neither of which seem mature. Now I am trying to install libgit2/pygit2. I have successfully installed them into the host packages environment, but now I need to get them installed in the virtualenv of the app I am building.
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygit2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pygit2/__init__.py", line 32, in <module>
import _pygit2
ImportError: libgit2.so.0: cannot open shared object file: No such file or directory
>>>
As you can see the current issue seems to be that the globally installed libgit2.so.0 cannot be found from within the virtualenv. Fair enough, that is what virtualenv is about after all,, sandboxing. So how do I go about linking/symlinking/building a version/copy of the libgit2.so for the virtualenv ?
I found the following script in a Gist that - when run while logged into a virtualenv -- will install the current libgit2/pygit2 together there in the venv.
https://gist.github.com/olivier-m/5755638
One note of caution, update the version numbers for both libraries to the same most recent version ( 0.20.0 at this time of writing ).

Categories