Can't find 'socket' - Python Help - Discussions on Python.org
Can't find 'socket' Python Help abrogard (arthur brogard) November 23, 2024, 2:35am 1 Just downloaded/installed latest Python (3.13) after four hours trying to get a script to run (with help (?) from gpt. And it still won’t go. PS C:\ytdlp> python.exe substackgetvid.py Traceback (most recent call last): File “C:\ytdlp\substackgetvid.py”, line 3, in import requests File “C:\Users\arthur\AppData\Local\Programs\Python\Python313\Lib\site-packages\requests_ init _.py”, line 43, in import urllib3 File “C:\Users\arthur\AppData\Local\Programs\Python\Python313\Lib\site-packages\urllib3_ init _.py”, line 14, in from . import exceptions File “C:\Users\arthur\AppData\Local\Programs\Python\Python313\Lib\site-packages\urllib3\exceptions.py”, line 3, in import socket File “C:\Users\arthur\AppData\Local\Programs\Python\Python313\Lib\socket.py”, line 52, in import _socket ImportError: DLL load failed while importing _socket: The specified module could not be found. so I tried installing ‘socket’ and got: PS C:\ytdlp> python.exe -m pip install --force-reinstall socket ERROR: Could not find a version that satisfies the requirement socket (from versions: none) [notice] A new release of pip is available: 24.2 → 24.3.1 [notice] To update, run: python.exe -m pip install --upgrade pip ERROR: No matching distribution ‘no matching distribution’ is the crux of my problems? what’s it mean? what to do? onePythonUser (Paul) November 23, 2024, 2:47am 2 use this instead: PS C:\ytdlp> py substackgetvid.py You don’t need the .exe .
You also don’t need the entire word python . You can just use py . However, first make sure that the module substackgetvid.py is located in C:\ytdlp . Or change the directory to where it is located. abrogard (arthur brogard) November 23, 2024, 3:09am 3 well thanks for that but it’s just a shorter better way of issuing the command. it don’t do nothing to change the results of it: can’t install socket. onePythonUser (Paul) November 23, 2024, 3:29am 4 Well, socket and _socket come pre-installed with Python .
Can you try re-installing Python ? abrogard (arthur brogard) November 23, 2024, 3:59am 5 Yep, as I said, I just did that. Have 3.13 now. Actually I have done it more than once this morning. It is a dll load fail, it says. so i made sure scripts and the exe are all on user and system paths. why is it trying to load it if it is core? barry-scott (Barry Scott) November 23, 2024, 8:43am 6 Try this. Start python as python -v At the >>> prompt type import socket Python should list where it is trying to import socket and _socket from.
Where does it try to load _socket from? Can you find _socket file in your python install? onePythonUser (Paul) November 23, 2024, 1:07pm 7 Can you open IDLE and run your script from there? Are the results the same or does it work when launched from there? abrogard (arthur brogard) November 24, 2024, 8:13am 8 Only just found your replies. sorry for the delay. answer second question first; i find these _socket files: C:\Users\arthur\AppData\Local\Programs\Python\Python313\DLLs_socket.pyd C:\Users\arthur\AppData\Local\Programs\Python\Python313\Lib\test\test_socketserver.py C:\Users\arthur\AppData\Local\Programs\Python\Python313\Lib\test\test_socket.py C:\Users\arthur\AppData\Local\Programs\Python\Python313\Lib\test\mock_socket.py for the socket search I get this: >>> import socket # C:\Users\arthur\AppData\Local\Programs\Python\Python313\Lib\__pycache__\socket.cpython-313.pyc matches C:\Users\arthur\AppData\Local\Programs\Python\Python313\Lib\socket.py # code object from 'C:\\Users\\arthur\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\__pycache__\\socket.cpython-313.pyc' unfortunately none of it makes much sense to me.
Any help if I publish the bit of code I am trying to run? I suppose not because it’s apparently a python install problem but if you like I can/will. abrogard (arthur brogard) November 24, 2024, 8:17am 9 I ran IDE and ran the code from there. and got this: python Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> python NameError: name 'python' is not defined ====================== RESTART: C:\ytdlp\substackgetvid.py ===================== Traceback (most recent call last): File "C:\ytdlp\substackgetvid.py", line 3, in <module> import requests File "C:\Users\arthur\AppData\Local\Programs\Python\Python313\Lib\site-packages\requests\__init__.py", line 48, in <module> from charset_normalizer import __version__ as charset_normalizer_version File "C:\Users\arthur\AppData\Local\Programs\Python\Python313\Lib\site-packages\charset_normalizer\__init__.py", line 24, in <module> from .api import from_bytes, from_fp, from_path, is_binary File "C:\Users\arthur\AppData\Local\Programs\Python\Python313\Lib\site-packages\charset_normalizer\api.py", line 5, in <module> from .cd import ( File "C:\Users\arthur\AppData\Local\Programs\Python\Python313\Lib\site-packages\charset_normalizer\cd.py", line 14, in <module> from .md import is_suspiciously_successive_range AttributeError: partially initialized module 'charset_normalizer' from 'C:\Users\arthur\AppData\Local\Programs\Python\Python313\Lib\site-packages\charset_normalizer\__init__.py' has no attribute 'md__mypyc' (most likely due to a circular import) barry-scott (Barry Scott) November 24, 2024, 9:56am 10 Please, do not post screen shots of text.
Use the pre-formatted text button </> . My python is installed for “all users” in c:\python3.13.win63 unlike your user install so the paths are not the same. Here is what I see on my Windows 11. >>> import socket # C:\python313.win64\Lib\__pycache__\socket.cpython-313.pyc matches C:\python313.win64\Lib\socket.py # code object from 'C:\\python313.win64\\Lib\\__pycache__\\socket.cpython-313.pyc' # extension module '_socket' loaded from 'C:\\python313.win64\\DLLs\\_socket.pyd' # extension module '_socket' executed from 'C:\\python313.win64\\DLLs\\_socket.pyd' import '_socket' # <_frozen_importlib_external.ExtensionFileLoader object at 0x000001B5325B3490> # C:\python313.win64\Lib\__pycache__\selectors.cpython-313.pyc matches C:\python313.win64\Lib\selectors.py # code object from 'C:\\python313.win64\\Lib\\__pycache__\\selectors.cpython-313.pyc' import 'math' # <class '_frozen_importlib.BuiltinImporter'> import 'selectors' # <_frozen_importlib_external.SourceFileLoader object at 0x000001B532A30590> import 'socket' # <_frozen_importlib_external.SourceFileLoader object at 0x000001B5327DE2D0> >>> In the past there have been a number of reasons for this type of problem. you have a user created socker.py file, rename it to something else.
Your installation of python was damaged. Try to uninstall completely and then install again. Anti-virus or software from your employer is breaking python. jeff5 (Jeff Allen) November 24, 2024, 12:19pm 11 It’s telling you where it is looking as it looks for socket and the things it depends on. The bit you post looks reasonable, but was it followed by a failure to find the DLL, or did it succeed in importing socket ? In the display Barry provides, you can see that CPython next finds a .pyd file in the DLL directory.
It is definitely the right approach to see if the basic import works without your application. If it fails, there’s something wrong with your installation/platform. Re-install, don’t pip install anything else yet, and see if you can track down how it breaks. If it succeeds with the bare import already, but fails in your application, then there is something about the application, or where you run it from, that is interfering with this process.
Try to creep up on the problem in that contex, maybe without requests e.g. if you put import socket at the top of your application file, does it fail there, or is it only inside requests that it fails? A useful diagnostic is sys.path. >>> import sys >>> sys.path It tells you where Python looks for things. Maybe something has changed it, or changes it as your application runs. jeff5 (Jeff A
The rest of this page is on the live site.