Sudden error in python 2.7 - python

I had installed python 2.7 which was working fine till today. Suddenly it closed with an application error which it failed to capture and now everytime while running it its throwing the below mentioned error.
To give you a brief background the RAM memmory reahed to 95% which might have led to initial python crashing
Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\lib\site-packages\scrapy-0.16.4-py2.7.egg\scrapy\cmdline.py"
, line 7, in <module>
from scrapy.crawler import CrawlerProcess
File "C:\Python27\lib\site-packages\scrapy-0.16.4-py2.7.egg\scrapy\crawler.py"
, line 3, in <module>
from twisted.internet import reactor, defer
File "C:\Python27\lib\site-packages\twisted\internet\reactor.py", line 38, in
<module>
from twisted.internet import default
File "C:\Python27\lib\site-packages\twisted\internet\default.py", line 56, in
<module>
install = _getInstallFunction(platform)
File "C:\Python27\lib\site-packages\twisted\internet\default.py", line 52, in
_getInstallFunction
from twisted.internet.selectreactor import install
File "C:\Python27\lib\site-packages\twisted\internet\selectreactor.py", line 1
8, in <module>
from twisted.internet import posixbase
File "C:\Python27\lib\site-packages\twisted\internet\posixbase.py", line 24, i
n <module>
from twisted.internet import error, udp, tcp
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 73, in <mod
ule>
from twisted.python.win32 import formatError as strerror
ImportError: cannot import name formatError

twisted module got corrupted due to the crash. Reinstalled the module and its working again.

It seems that some third-party packages are the ones at fault here. Try re-installing them or uninstalling them completely. If you are working with twisted try going up to python3, it has great support and hopefully the latest install fixed corruption issues.

Related

How to make a Flask application in venv works with Anaconda

I'm trying to start a flask application, with flask run, (which was working fine before I installed Anaconda), and I'm getting the following stack trace
Traceback (most recent call last):
File "C:\Users\Rodrigo\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\Rodrigo\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Rodrigo\Documents\Project1\frontEnd\venv\Scripts\flask.exe\__main__.py", line 5, in <module>
File "C:\Users\Rodrigo\Documents\Project1\frontEnd\venv\lib\site-packages\flask\__init__.py", line 19, in <module>
from jinja2 import Markup, escape
File "C:\Users\Rodrigo\Documents\Project1\frontEnd\venv\lib\site-packages\jinja2\__init__.py", line 82, in <module>
_patch_async()
File "C:\Users\Rodrigo\Documents\Project1\frontEnd\venv\lib\site-packages\jinja2\__init__.py", line 78, in _patch_async
from jinja2.asyncsupport import patch_all
File "C:\Users\Rodrigo\Documents\Project1\frontEnd\venv\lib\site-packages\jinja2\asyncsupport.py", line 13, in <module>
import asyncio
File "C:\Users\Rodrigo\Anaconda3\lib\asyncio\__init__.py", line 8, in <module>
from .base_events import *
File "C:\Users\Rodrigo\Anaconda3\lib\asyncio\base_events.py", line 39, in <module>
from . import events
File "C:\Users\Rodrigo\Anaconda3\lib\asyncio\events.py", line 14, in <module>
import contextvars
File "C:\Users\Rodrigo\Anaconda3\lib\contextvars.py", line 1, in <module>
from _contextvars import Context, ContextVar, Token, copy_context
ModuleNotFoundError: No module named '_contextvars'
The Python version at the system level is 3.7.3
The Python version at venv level is 3.7.0
I've already tried to install contextvars, but it only upgraded an older version and did not fix the problem. In both system level and venv level contextvars requisite is already satisfied.
I'm running this on Windows 10.
Any idea on what can be causing this?
I have the same issue when using python 3.7.2 on Windows 7.
This is a known bug and should be resolved.
https://bugs.python.org/issue34691
Updating to python 3.7.3 resolved the issue (for me).
Try to update your venv level to 3.7.3

I'm getting ModuleNotFoundError: No module named _socket on ubuntu 18.04

I installed Anaconda3 on ubuntu and changed the path to ~/anaconda/bin in .bashrc file then I'm trying to install keras It's throwing this error.
hemanth#specter:~$ python3 -m pip install keras
Traceback (most recent call last):
File "/home/hemanth/anaconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/hemanth/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/hemanth/anaconda3/lib/python3.7/site-packages/pip/__main__.py", line 16, in <module>
from pip._internal import main as _main # isort:skip # noqa
File "/home/hemanth/anaconda3/lib/python3.7/site-packages/pip/_internal/__init__.py", line 19, in <module>
from pip._vendor.urllib3.exceptions import DependencyWarning
File "/home/hemanth/anaconda3/lib/python3.7/site-packages/pip/_vendor/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/home/hemanth/anaconda3/lib/python3.7/site-packages/pip/_vendor/urllib3/connectionpool.py", line 7, in <module>
from socket import error as SocketError, timeout as SocketTimeout
File "/home/hemanth/anaconda3/lib/python3.7/socket.py", line 49, in <module>
import _socket
ModuleNotFoundError: No module named '_socket'
I tried this command and it is working fine.
however, try to install socket using pip install sockets and then again try installing keras.

Pyinstaller 3.4 Not Working on Windows 10 with Python 2.7

I have recently reinstalled Windows 10. I am using Python 2.7 and trying to make a small executable using Pyinstaller 3.4. and I get the following error:
C:\python_programs\py_live>pyinstaller g_uplink.py
Traceback (most recent call last):
File "C:\Python27\Lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\Lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\Scripts\pyinstaller.exe\__main__.py", line 5, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\__init__.py", line 16, in <module>
from . import compat
File "C:\Python27\Lib\site-packages\PyInstaller\compat.py", line 212, in <module>
from win32ctypes.pywin32 import pywintypes # noqa: F401
File "C:\Python27\Lib\site-packages\win32ctypes\pywin32\__init__.py", line 11, in <module>
from win32ctypes.pywin32 import win32api
File "C:\Python27\Lib\site-packages\win32ctypes\pywin32\win32api.py", line 12, in <module>
from win32ctypes.core import (
File "C:\Python27\Lib\site-packages\win32ctypes\core\__init__.py", line 36, in load_module
module = importlib.import_module(self.redirect_module)
File "C:\Python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Python27\Lib\site-packages\win32ctypes\core\cffi\_dll.py", line 19, in <module>
""")
File "C:\Python27\Lib\site-packages\cffi\api.py", line 107, in cdef
self._parser.parse(csource, override=override, packed=packed)
File "C:\Python27\Lib\site-packages\cffi\cparser.py", line 167, in parse
self._internal_parse(csource)
File "C:\Python27\Lib\site-packages\cffi\cparser.py", line 173, in _internal_parse
ast, macros, csource = self._parse(csource)
File "C:\Python27\Lib\site-packages\cffi\cparser.py", line 130, in _parse
self.convert_pycparser_error(e, csource)
File "C:\Python27\Lib\site-packages\cffi\cparser.py", line 159, in convert_pycparser_error
raise api.CDefError(msg)
cffi.api.CDefError: cannot parse "HMODULE WINAPI LoadLibraryExW(LPCTSTR lpFileName, HANDLE hFile, DWORD dwFlags);"
:16:16: before: LoadLibraryExW
Does anyone know what is going on? It worked fine with the same file before reinstalling everything.
I ended up just downgrading Pyinstaller to 3.3 and that worked fine for my application.
pip install pyinstaller==3.3
Note: 3.0 also works as stated in my comment. I successfully tried 3.3 and am now using it because its newer.
As per Mike's own input, installing PyInstaller 3.0 will fix the problem. Just tried on Win7 Enterprise and it works just fine.

Trying to install mysql-python: "No module named urllib3"

I'm trying to look around on this issue but so far nothing I've found has fixed it. I am not that familiar with Python and I'm working with someone else's script. I am on Windows 10 (64-bit).
Executing this command: pip install mysql-python
And getting this error:
Traceback (most recent call last):
File "C:\Python27\Lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\Lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\Scripts\pip.exe\__main__.py", line 5, in <module>
File "C:\Python27\lib\site-packages\pip\__init__.py", line 15, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "C:\Python27\lib\site-packages\pip\vcs\mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "C:\Python27\lib\site-packages\pip\download.py", line 38, in <module>
from pip._vendor import requests, six
File "C:\Python27\lib\site-packages\pip\_vendor\requests\__init__.py", line 58, in <module>
from . import utils
File "C:\Python27\lib\site-packages\pip\_vendor\requests\utils.py", line 26, in <module>
from .compat import parse_http_list as _parse_list_header
File "C:\Python27\lib\site-packages\pip\_vendor\requests\compat.py", line 7, in <module>
from .packages import chardet
File "C:\Python27\lib\site-packages\pip\_vendor\requests\packages\__init__.py", line 29, in <module>
import urllib3
ImportError: No module named urllib3
The python module that you are trying to install will probably require you to compile it which makes the task much harder for a newbie.
Instead, I would recommend you to use a pure-python module like https://github.com/PyMySQL/PyMySQL -- which is much easier to install because you do not have to compile it.
Usually I recommend anyone that is trying to work with databases in Python to use SQLAlchemy, mainly because this allows you to use a single interface when you deal with the database, one that does not depends on the database-driver being used.
Read the answer from
python3 sqlalchemy pymysql connect string in order to get an idea about how to use pymysql via sqlalchemy.
wget https://pypi.python.org/packages/3b/f0/e763169124e3f5db0926bc3dbfcd580a105f9ca44cf5d8e6c7a803c9f6b5/urllib3-1.16.tar.gz#md5=fcaab1c5385c57deeb7053d3d7d81d59
tar xvf urllib3-1.16.tar.gz && cd urllib3-1.1
python setup.py install

pip broke after uninstalling a module

I used pip uninstall on shapely and got an exception, which I did not save.
Since then every pip or easy install command will pop this exception :
Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\Scripts\pip.exe\__main__.py", line 5, in <module>
File "C:\Python27\lib\site-packages\pip\__init__.py", line 13, in <module>
from pip.utils import get_installed_distributions, get_prog
File "C:\Python27\lib\site-packages\pip\utils\__init__.py", line 17, in <module>
from pip.compat import console_to_str, stdlib_pkgs
File "C:\Python27\lib\site-packages\pip\compat\__init__.py", line 14, in <module>
from pip.compat.dictconfig import dictConfig as logging_dictConfig
File "C:\Python27\lib\site-packages\pip\compat\dictconfig.py", line 22, in <module>
import logging.handlers
File "C:\Python27\lib\logging\handlers.py", line 27, in <module>
import logging, socket, os, cPickle, struct, time, re
File "C:\Python27\lib\socket.py", line 47, in <module>
import _socket
ImportError: No module named _socket
Any ideas?
See this bug.
Off the top, pip uninstall shapely seems to be removing the top dlls from the Python installations. This is why you see the error on every pip command after.

Categories