When opening a jupyter notebook, I get the following errors. Any idea how to fix this? I'm running on ubuntu 16.04 with Anaconda 2. Tried uninstalling and reinstalling ipython and tried doing that through both pip and conda. Didn't help.
[E 13:52:02.191 NotebookApp] Unhandled error in API request
Traceback (most recent call last):
File "/home/user/anaconda2/lib/python2.7/site-packages/notebook/base/handlers.py", line 457, in wrapper
result = yield gen.maybe_future(method(self, *args, **kwargs))
File "/home/user/anaconda2/lib/python2.7/site-packages/notebook/services/kernelspecs/handlers.py", line 56, in get
for kernel_name in ksm.find_kernel_specs():
File "/home/user/anaconda2/lib/python2.7/site-packages/nb_conda_kernels/manager.py", line 192, in find_kernel_specs
kspecs = super(CondaKernelSpecManager, self).find_kernel_specs()
File "/home/user/anaconda2/lib/python2.7/site-packages/jupyter_client/kernelspec.py", line 128, in find_kernel_specs
for kernel_dir in self.kernel_dirs:
File "/home/user/anaconda2/lib/python2.7/site-packages/traitlets/traitlets.py", line 554, in __get__
return self.get(obj, cls)
File "/home/user/anaconda2/lib/python2.7/site-packages/traitlets/traitlets.py", line 533, in get
value = self._validate(obj, dynamic_default())
File "/home/user/anaconda2/lib/python2.7/site-packages/jupyter_client/kernelspec.py", line 114, in _kernel_dirs_default
from IPython.paths import get_ipython_dir
File "/home/user/anaconda2/lib/python2.7/site-packages/IPython/__init__.py", line 48, in <module>
from .core.application import Application
File "/home/user/anaconda2/lib/python2.7/site-packages/IPython/core/application.py", line 25, in <module>
from IPython.core import release, crashhandler
File "/home/user/anaconda2/lib/python2.7/site-packages/IPython/core/crashhandler.py", line 28, in <module>
from IPython.core import ultratb
File "/home/user/anaconda2/lib/python2.7/site-packages/IPython/core/ultratb.py", line 131, in <module>
import IPython.utils.colorable as colorable
AttributeError: 'module' object has no attribute 'utils'
[E 13:52:02.192 NotebookApp] {
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Host": "localhost:8888",
"Accept": "*/*",
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0",
"Connection": "keep-alive",
"X-Requested-With": "XMLHttpRequest",
"Referer": "http://localhost:8888/tree"
}
[E 13:52:02.192 NotebookApp] 500 GET /api/kernelspecs (127.0.0.1) 3.10ms referer=http://localhost:8888/tree
Uninstalling Anaconda2 and installing Anaconda3 instead fixed this issue.
Related
Linux Mint 20.3
I try to run pgadmin4 like this:
./pgadmin4env/bin/pgadmin4&
But get error:
[1] 3994127
(pgadmin4env) alexeij#workstation:~/pgadmin4/pgadmin4_dir$ Traceback (most recent call last):
File "./pgadmin4env/bin/pgadmin4", line 5, in <module>
from pgadmin4.pgAdmin4 import main
File "/home/alexeij/pgadmin4/pgadmin4_dir/pgadmin4env/lib/python3.8/site-packages/pgadmin4/pgAdmin4.py", line 35, in <module>
import config
File "/home/alexeij/pgadmin4/pgadmin4_dir/pgadmin4env/lib/python3.8/site-packages/pgadmin4/config.py", line 25, in <module>
from pgadmin.utils import env, IS_WIN, fs_short_path
File "/home/alexeij/pgadmin4/pgadmin4_dir/pgadmin4env/lib/python3.8/site-packages/pgadmin4/pgadmin/__init__.py", line 21, in <module>
from flask import Flask, abort, request, current_app, session, url_for
File "/home/alexeij/pgadmin4/pgadmin4_dir/pgadmin4env/lib/python3.8/site-packages/flask/__init__.py", line 19, in <module>
from jinja2 import Markup, escape
ImportError: cannot import name 'Markup' from 'jinja2' (/home/alexeij/pgadmin4/pgadmin4_dir/pgadmin4env/lib/python3.8/site-packages/jinja2/__init__.py)
i am trying to run a python program which takes input from the users like,directory name,file name and its content and then i try to create the directory in the current path with the file and then write the data into it but i get an error that "os has no attribute mkdir".
//Code
import os
print(os.getcwd())
class createfile:
__name=''
__file_name=''
__input_text=''
def read_and_create(self):
name = input("Enter the directory name, you want to create: ")
os.mkdir(self.__name)
#sdos.mkdir(self.__name)
self.__file_name=input("Enter the file name, you want to create: ")
f=open(self.___file_name,'w')
self.__input_text=input("Enter the text : ")
f.write(self.__input_text)
f.close()
def read_file_content(self):
x=open(self.__file_name,'r')
print(x.read())
o=createfile()
o.read_and_create()
o.read_file_content()
this is the error i got using Pycharm.
> "C:\Users\Aryan
> Kumar\AppData\Local\Programs\Python\Python37-32\python.exe"
> "C:/Users/Aryan Kumar/Desktop/0/os.py"
> Fatal Python error: initsite: Failed to import the site module
> Traceback (most recent call last):
> File "C:\Users\Aryan Kumar\AppData\Local\Programs\Python\Python37-32\lib\site.py", line 73,
> in <module>
> import os
> File "C:\Users\Aryan Kumar\Desktop\0\os.py", line 2, in <module>
> print(os.getcwd())
> AttributeError: module 'os' has no attribute 'getcwd'
>
> Process finished with exit code 1
this is the error i got using Spyder ide in anaconda environment
runfile('C:/Users/Aryan Kumar/Desktop/0/untitled0.py', wdir='C:/Users/Aryan Kumar/Desktop/0')
C:\Users\Aryan Kumar\Desktop\0
Enter the directory name, you want to create: aac
Traceback (most recent call last):
File "<ipython-input-4-fb1c179833e1>", line 1, in <module>
runfile('C:/Users/Aryan Kumar/Desktop/0/untitled0.py', wdir='C:/Users/Aryan Kumar/Desktop/0')
File "C:\Users\Aryan Kumar\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 709, in runfile
execfile(filename, namespace)
File "C:\Users\Aryan Kumar\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Aryan Kumar/Desktop/0/untitled0.py", line 32, in <module>
o.read_and_create()
File "C:/Users/Aryan Kumar/Desktop/0/untitled0.py", line 18, in read_and_create
os.mkdir(self.__name)
FileNotFoundError: [WinError 3] The system cannot find the path specified: ''
This is an old question but someone might have the same problem. I also received the following error: AttributeError: module 'os' has no attribute 'getcwd'. This is because the file name is os.py. Problem solved after changing the file name.
Also found that a similar answer also provided in a different question:
https://stackoverflow.com/a/43565408/298160
Use os.curdir() in Python3 instead of os.cwd()
I have made it to which the model in django is built, but once adding data and clicking save my app crash
i get GDAL exception - OGR Failure, and it highlights in the crash page " {{ field.field }}" as the reason for the error.
here's screen shot Admin view for adding data to the model
i get this right away after clicking save
Anyone been through this? any help?
Thanks
Update :
I'm getting this error :
[12/Apr/2019 14:38:46] "GET /static/admin/img/gis/move_vertex_off.svg HTTP/1.1"
200 1129
[12/Apr/2019 14:39:14] "GET /static/admin/img/gis/move_vertex_on.svg HTTP/1.1" 2
00 1129
GDAL_ERROR 4: b'Unable to open EPSG support file gcs.csv.\nTry setting the GDAL_
DATA environment variable to point to the\ndirectory containing EPSG csv files.'
Internal Server Error: /admin/trial2/shop/add/
Traceback (most recent call last):
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\core\
handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\core\
handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\core\
handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\contr
ib\admin\options.py", line 606, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\utils
\decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\views
\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\contr
ib\admin\sites.py", line 223, in inner
return view(request, *args, **kwargs)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\contr
ib\admin\options.py", line 1634, in add_view
return self.changeform_view(request, None, form_url, extra_context)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\utils
\decorators.py", line 45, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\utils
\decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\contr
ib\admin\options.py", line 1522, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\contr
ib\admin\options.py", line 1554, in _changeform_view
form_validated = form.is_valid()
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\forms
\forms.py", line 185, in is_valid
return self.is_bound and not self.errors
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\forms
\forms.py", line 180, in errors
self.full_clean()
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\forms
\forms.py", line 381, in full_clean
self._clean_fields()
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\forms
\forms.py", line 399, in _clean_fields
value = field.clean(value)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\contr
ib\gis\forms\fields.py", line 79, in clean
geom.transform(self.srid)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\contr
ib\gis\geos\geometry.py", line 471, in transform
g = gdal.OGRGeometry(self._ogr_ptr(), srid)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\contr
ib\gis\gdal\geometries.py", line 115, in __init__
self.srs = srs
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\contr
ib\gis\gdal\geometries.py", line 284, in _set_srs
sr = SpatialReference(srs)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\contr
ib\gis\gdal\srs.py", line 92, in __init__
self.import_epsg(srs_input)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\contr
ib\gis\gdal\srs.py", line 277, in import_epsg
capi.from_epsg(self.ptr, epsg)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\contr
ib\gis\gdal\prototypes\errcheck.py", line 118, in check_errcode
check_err(result, cpl=cpl)
File "C:\Users\lgcge\Documents\copypostgis\venv\lib\site-packages\django\contr
ib\gis\gdal\error.py", line 59, in check_err
raise e(msg)
django.contrib.gis.gdal.error.GDALException: OGR failure.
[12/Apr/2019 14:39:45] "POST /admin/trial2/shop/add/ HTTP/1.1" 500 160518
admin.py :
from django import forms
from django.contrib.gis import admin
from django.contrib.gis.db import models
from django.contrib.gis.admin import OSMGeoAdmin
from .models import Shop
#admin.register(Shop)
class ShopAdmin(OSMGeoAdmin):
list_display = ('name', 'location')
model.py
from __future__ import unicode_literals
from django.contrib.gis.db import models
from django.contrib.gis.geos import Point
class Shop(models.Model):
name = models.CharField(max_length=100)
location = models.PointField()
address = models.CharField(max_length=100)
city = models.CharField(max_length=50)
Apologies for copy/pasting and only slightly modifying #Kiwi's answer. I tried adding a comment to the original answer but I could not add formatted code.
It seems now that you cannot install the 64 bit version of OSGEO4W any more. I installed the only version available here and modified #Kiwi's answer to reflect the lack of 64 bit. I'm on Windows 10. All works fine with the below.
import platform
import environ
WINDOWS = platform.system() == "Windows"
if WINDOWS:
# the below needs to change for linux
GDAL_LIBRARY_PATH = r'C:\OSGeo4W\bin\gdal303.dll'
GEOS_LIBRARY_PATH = r'C:\OSGeo4W\bin\geos_c.dll'
OSGEO4W = r"C:\OSGeo4W"
os.environ['OSGEO4W_ROOT'] = OSGEO4W
os.environ['GDAL_DATA'] = "C:\Program Files\GDAL\gdal-data" # OSGEO4W + r"\share\gdal"
os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
os.environ['PATH'] = OSGEO4W + r"\bin;" + os.environ['PATH']
if os.name == 'nt':
import platform
OSGEO4W = r"C:\OSGeo4W"
if '64' in platform.architecture()[0]:
OSGEO4W += "64"
assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
os.environ['OSGEO4W_ROOT'] = OSGEO4W
os.environ['GDAL_DATA'] = "C:\Program Files\GDAL\gdal-data" #OSGEO4W + r"\share\gdal"
os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
os.environ['PATH'] = OSGEO4W + r"\bin;" + os.environ['PATH']
the issue was that this code enforces the paths defined in it over geodjango, so even if you set system variables, still this code would dominate over the system variables.
If anyone has issue with OGR don't hesitate to comment
I had the same problem and this is how I was able to solve it.
first check your GDAL version and GEOS
by running following scripts
gdal-config --version
and
geos-config --version
If the versions of GDAL and GEOS do not match, you will need to either install a compatible version of GEOS or update GDAL to a version that is compatible with the version of GEOS you have installed.
For example if you have GEOS version 3.8.0 or above you will need to upgrade GDAL >= 3.1.2
Today I have tried use docker-compose and got next error:
>>docker-compose
Traceback (most recent call last):
File "/usr/bin/docker-compose", line 9, in <module>
load_entry_point('docker-compose==1.7.1', 'console_scripts', 'docker-compose')()
File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 558, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2682, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2355, in load
return self.resolve()
File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2361, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/lib/python2.7/site-packages/compose/cli/main.py", line 14, in <module>
from . import errors
File "/usr/lib/python2.7/site-packages/compose/cli/errors.py", line 9, in <module>
from docker.errors import APIError
File "/usr/lib/python2.7/site-packages/docker/__init__.py", line 20, in <module>
from .client import Client, AutoVersionClient, from_env # flake8: noqa
File "/usr/lib/python2.7/site-packages/docker/client.py", line 22, in <module>
import websocket
File "/usr/lib/python2.7/site-packages/websocket/__init__.py", line 22, in <module>
from ._core import *
File "/usr/lib/python2.7/site-packages/websocket/_core.py", line 39, in <module>
from ._socket import *
File "/usr/lib/python2.7/site-packages/websocket/_socket.py", line 28, in <module>
from ._ssl_compat import *
AttributeError: 'module' object has no attribute 'ssl'
OS: OpenSuse Leap 42.1
Docker-compose: 1.7.1
Docker: 1.11.2
libopenssl-devel installed
Downgrade OpennSSL to version 1.0.1i-15.1 from 1.0.1i-2.36.1 has fixed my problem.
I'm having trouble running jupyter nbconvert.
It always shows the following error trace (even with a notebook with a few vanilla cells)
Traceback (most recent call last):
File "/home/miguel/.virtualenvs/ipython/bin/jupyter-nbconvert", line 11, in <module>
sys.exit(main())
File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/jupyter_core/application.py", line 267, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/traitlets/config/application.py", line 596, in launch_instance
app.start()
File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/nbconvert/nbconvertapp.py", line 293, in start
self.convert_notebooks()
File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/nbconvert/nbconvertapp.py", line 447, in convert_notebooks
self.exporter = cls(config=self.config)
File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/nbconvert/exporters/templateexporter.py", line 151, in __init__
super(TemplateExporter, self).__init__(config=config, **kw)
File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/nbconvert/exporters/exporter.py", line 101, in __init__
self._init_preprocessors()
File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/nbconvert/exporters/exporter.py", line 250, in _init_preprocessors
self.register_preprocessor(preprocessor, enabled=True)
File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/nbconvert/exporters/exporter.py", line 211, in register_preprocessor
preprocessor_cls = import_item(preprocessor)
File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/ipython_genutils/importstring.py", line 31, in import_item
module = __import__(package, fromlist=[obj])
TypeError: Item in ``from list'' not a string
It might be related with the nbextensions which I recently installed, since some days ago the jupyter nbconvert command used to work perfectly.
Today, I've been having some trouble installing the nbextensions. I tried using conda, but finally the it worked when I followed the instructions from here.
I had the same problem today. It seems this is a bug in nbconvert, as documented here. The solution is to edit your "jupyter_nbconvert_config.json" file. For me, this was located in my home directory by default: /home/me/.jupyter/jupyter_nbconvert_config.json
There, I changed the preprocessor strings, adding an "r" in front of them:
{
"Exporter": {
"template_path": [
".",
"/usr/lib/python2.7/site- packages/jupyter_contrib_nbextensions/templates"
],
"preprocessors": [
r"jupyter_contrib_nbextensions.nbconvert_support.CodeFoldingPreprocessor",
r"jupyter_contrib_nbextensions.nbconvert_support.PyMarkdownPreprocessor"
]
},
"NbConvertApp": {
"postprocessor_class": "jupyter_contrib_nbextensions.nbconvert_support.EmbedPostProcessor"
},
"version": 1
}
Found a solution here.
Basically, you need to remove or rename your jupyter_nbconvert_config file.
This bug was fixed recently, see the details here. Run a full update for ipython or, to fix manually:
change line 31 in your ipython_genutils/importstring.py from
module = __import__(package, fromlist=[obj])
to
module = __import__(package, fromlist=[str(obj)])