NLTK import error - windows

I'm new to Python and NLTK. I've been trying to find a solution to my problem but have not found one yet and was hoping someone could help me.
I'm currently running 64bit Windows 8. I've followed the instruction in the NLTK website (http://www.nltk.org/install.html). I might have installed a 64bit version Python in the first place but have removed it and reinstall 32bit version Python. Now I'm having the following problem:
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import nltk
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import nltk
File "C:\Python27\lib\site-packages\nltk\__init__.py", line 117, in <module>
from nltk.align import *
File "C:\Python27\lib\site-packages\nltk\align\__init__.py", line 15, in <module>
from nltk.align.ibm1 import IBMModel1
File "C:\Python27\lib\site-packages\nltk\align\ibm1.py", line 18, in <module>
from nltk.corpus import comtrans
File "C:\Python27\lib\site-packages\nltk\corpus\__init__.py", line 64, in <module>
from nltk.tokenize import RegexpTokenizer
File "C:\Python27\lib\site-packages\nltk\tokenize\__init__.py", line 62, in <module>
from nltk.data import load
File "C:\Python27\lib\site-packages\nltk\data.py", line 74, in <module>
if os.path.expanduser('~/') != '~/':
File "C:\Python27\lib\ntpath.py", line 310, in expanduser
return userhome + path[i:]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xac in position 9: ordinal not in range(128)
>>>
Any ideas?

I solve this by changing my operating system locale for non-Unicode programs:
1 – Go to Control Panel
2 – Click “Clock, Language and Region”
3 – Click “Regional and Language Options”
4 – Go under “Administrative” tab
5 – current system locale (for non-Unicode) is displayed, to change it click “Change system locale”
6 – Then just choose English! After a reboot, done!

Related

Anaconda Jypiter wont start, Spyder reporting errors

I did try uninstalling and installing Anaconda, but the problem remains the same.
Windows 10 x64, latest Anaconda
Installation goes fine, but when I start Spyder it reports this:
"You have missing dependencies, nbconvert >=4.0": None. However, nbconvert is already installed.
It prompted me to install Kite, when I did it says Kite installation error.
When I try to launch jupyter lab I get this:
Traceback (most recent call last): File
"C:\Users\Aleksandar\anaconda3\Scripts\jupyter-lab-script.py", line 5,
in from jupyterlab.labapp import main File
"C:\Users\Aleksandar\anaconda3\lib\site-packages\jupyterlab\labapp.py",
line 14, in from jupyterlab_server import slugify,
WORKSPACE_EXTENSION File
"C:\Users\Aleksandar\anaconda3\lib\site-packages\jupyterlab_server__init__.py",
line 4, in from .app import LabServerApp File
"C:\Users\Aleksandar\anaconda3\lib\site-packages\jupyterlab_server\app.py",
line 9, in from .server import ServerApp File
"C:\Users\Aleksandar\anaconda3\lib\site-packages\jupyterlab_server\server.py",
line 14, in from notebook.base.handlers import ( File
"C:\Users\Aleksandar\anaconda3\lib\site-packages\notebook\base\handlers.py",
line 22, in from tornado import web, gen, escape, httputil File
"C:\Users\Aleksandar\anaconda3\lib\site-packages\tornado\web.py", line
87, in from tornado.httpserver import HTTPServer File
"C:\Users\Aleksandar\anaconda3\lib\site-packages\tornado\httpserver.py",
line 32, in from tornado.http1connection import
HTTP1ServerConnection, HTTP1ConnectionParameters File
"C:\Users\Aleksandar\anaconda3\lib\site-packages\tornado\http1connection.py",
line 34, in from tornado import iostream File
"C:\Users\Aleksandar\anaconda3\lib\site-packages\tornado\iostream.py",
line 40, in from tornado.netutil import ssl_wrap_socket,
_client_ssl_defaults, _server_ssl_defaults File "C:\Users\Aleksandar\anaconda3\lib\site-packages\tornado\netutil.py",
line 39, in
_client_ssl_defaults = ssl.create_default_context(ssl.Purpose.SERVER_AUTH) File
"C:\Users\Aleksandar\anaconda3\lib\ssl.py", line 589, in
create_default_context context.load_default_certs(purpose) File
"C:\Users\Aleksandar\anaconda3\lib\ssl.py", line 490, in
load_default_certs self._load_windows_store_certs(storename, purpose)
File "C:\Users\Aleksandar\anaconda3\lib\ssl.py", line 482, in
_load_windows_store_certs self.load_verify_locations(cadata=certs) ssl.SSLError: nested asn1 error (_ssl.c:4003)
Found an error. It is caused by the certificates issued by Serbian government. The solution is changing ssl.py like this:
def _load_windows_store_certs(self, storename, purpose):
certs = bytearray()
try:
for cert, encoding, trust in enum_certificates(storename):
# CA certs are never PKCS#7 encoded
if encoding == "x509_asn":
if trust is True or purpose.oid in trust:
if "MUP Republike Srbije" not in str(cert):
certs.extend(cert)
except PermissionError:
warnings.warn("unable to enumerate Windows certificate store")
if certs:
self.load_verify_locations(cadata=certs)
return certs`

Failed to start spyder kernel after setting Python interpreter to new environment

I made a new environment where I installed geopandas, xarray, and regionmask. When I tried to switch environment using the modular approach (by installing spyder-kernels in the new environment and indicating the new path to the environment in the Python interpreter, as indicated here: https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder#the-modular-approach), an error persists while starting the kernel:
Traceback (most recent call last):
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\site‑packages\spyder_kernels\console\__main__.py", line 11, in
start.main()
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\site‑packages\spyder_kernels\console\start.py", line 288, in main
import_spydercustomize()
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\site‑packages\spyder_kernels\console\start.py", line 39, in import_spydercustomize
import spydercustomize
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\site‑packages\spyder_kernels\customize\spydercustomize.py", line 27, in
from spyder_kernels.comms.frontendcomm import CommError, frontend_request
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\site‑packages\spyder_kernels\comms\frontendcomm.py", line 17, in
from jupyter_client.localinterfaces import localhost
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\site‑packages\jupyter_client\__init__.py", line 4, in
from .connect import *
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\site‑packages\jupyter_client\connect.py", line 21, in
import zmq
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\site‑packages\zmq\__init__.py", line 47, in
from zmq import backend
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\site‑packages\zmq\backend\__init__.py", line 40, in
reraise(*exc_info)
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\site‑packages\zmq\utils\sixcerpt.py", line 34, in reraise
raise value
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\site‑packages\zmq\backend\__init__.py", line 27, in
_ns = select_backend(first)
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\site‑packages\zmq\backend\select.py", line 28, in select_backend
mod = __import__(name, fromlist=public_api)
File "C:\Users\Justin\anaconda3\envs\geo_env\lib\site‑packages\zmq\backend\cython\__init__.py", line 6, in
from . import (constants, error, message, context,
ImportError: DLL load failed while importing error: The specified module could not be found.
How can I debug this?
(Spyder maintainer here) This problem was fixed in this pull request, which is going to be part of Spyder 4.1.0, to be released later in March 2020.

multiprocessing starmap AttributeError: 'NoneType' object has no attribute 'write'

My parallelized script was working for a while. I used the multiprocessing library and the function starmap for it. But now when I'm trying to run it the following AttributeErroris displayed:
Python 3.6.5 | packaged by conda-forge | (default, Apr 6 2018,
16:13:55) [MSC v.1900 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 6.3.1 -- An enhanced Interactive Python.
Traceback (most recent call last):
File "<ipython-input-1-d3a2b861c70a>", line 1, in <module>
runfile('E:/Python/E2Oeval.py', wdir='E:/Python')
File "C:\Users\AppData\Local\conda\conda\envs\py36\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "C:\Users\AppData\Local\conda\conda\envs\py36\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "E:/Python/E2Oeval.py", line 1227, in <module>
df_Qobs_percs, df_Qsim_percs, df_sdQsim_percs, df_KGE_alpha, df_KGE_beta, df_KGE_r = ee.main_par(db_Qobs_meta_dir, Ens_mean_dir, Ens_sd_dir, db_Qobs_dir)
File "E:/Python/E2Oeval.py", line 835, in main_par
res = p.starmap(self.main, subsets)
File "C:\Users\AppData\Local\conda\conda\envs\py36\lib\multiprocessing\pool.py", line 274, in starmap
return self._map_async(func, iterable, starmapstar, chunksize).get()
File "C:\Users\AppData\Local\conda\conda\envs\py36\lib\multiprocessing\pool.py", line 644, in get
raise self._value
AttributeError: 'NoneType' object has no attribute 'write'
The error only occurs on windows, for unix the code is working. I need to run it on the windows machine since it requires some CPU power which is not given by notebook. Has anyone an idea how to detect the NoneType object causing the error?

Importing pandas in windows

I tried multiple methods with Anaconda and python both using version 3.6 and when I import pandas I'm getting the following error in my Windows machine
import pandas
File "D:\python3\lib\site-packages\pandas\__init__.py", line 22, in <module>
from pandas.compat.numpy import *
File "D:\python3\lib\site-packages\pandas\compat\__init__.py", line 59, in <module>
import http.client as httplib
File "D:\python3\lib\http\client.py", line 71, in <module>
import email.parser
File "D:\email.py", line 5, in <module>
import pandas.io.sql as psql
File "D:\python3\lib\site-packages\pandas\io\sql.py", line 14, in <module>
import pandas.lib as lib
File "pandas\lib.pyx", line 1, in init pandas.lib (pandas\lib.c:90879)
File "pandas\tslib.pyx", line 59, in init pandas.tslib (pandas\tslib.c:115313)
ImportError: cannot import name is_platform_windows
It seems to be environment related but I can't find anything related to this issue when I google this.
Looks like it was picking anything python script in my folder called email.py and that's causing the issue.

Installing scapy3 on windows 7

Pretty new to both scapy and python so apologies for what may be a thickheaded question.
I know that it is new and may have issues on Windows but I have successfully installed scapy3 on Windows 2012r2 and Ubuntu Linux. Unfortunately, I actually hope to use it on Windows 7 and am getting the following error message:
Traceback (most recent call last):
File "C:\Python35\Scripts\\scapy", line 25, in <module>
interact()
File "C:\Python35\lib\site-packages\scapy\main.py", line 293, in interact
scapy_builtins = __import__("scapy.all",globals(),locals(),".").__dict__
File "C:\Python35\lib\site-packages\scapy\all.py", line 16, in <module>
from .arch import *
File "C:\Python35\lib\site-packages\scapy\arch\__init__.py", line 95, in <module>
from .windows import *
File "C:\Python35\lib\site-packages\scapy\arch\windows\__init__.py", line 200, in <module>
ifaces.load_from_powershell()
File "C:\Python35\lib\site-packages\scapy\arch\windows\__init__.py", line 151, in load_from_powers
hell
for i in get_windows_if_list():
File "C:\Python35\lib\site-packages\scapy\arch\windows\__init__.py", line 86, in get_windows_if_list
name, value = [ j.strip() for j in i.split(':') ]
ValueError: too many values to unpack (expected 2)
I have searched via google and on stackoverflow but have not found a solution.
Any guidance appreciated.
platform is Windows 7 and python35
Late answer: you are using a fork of scapy that does not officially supports windows 7.
Since very recently, the original secdev/scapy fork supports Python 3, so there is need to keep using the one not supporting windows 7 :-)
Feel free to have a look at
https://github.com/secdev/scapy

Resources