I am an amateur at python eve. In the process of running some demo api for the same I get value error. I am running this code in ipython desktop app.
from flask import jsonify
from eve import Eve
app = Eve()
#app.route('/average/<user>')
def compute_average(user):
return jsonify({user:47})
if __name__=='__main__':
app.run(debug=True)
On running this code I get the following error:
ValueError Traceback (most recent call last)
C:\Users\***\Documents\Python Scripts\test.py in <module>()
1 from flask import jsonify
2 from eve import Eve
----> 3 app = Eve()
4
5 #app.route('/average/<user>')
C:\Users\***\Anaconda2\lib\site-packages\eve\flaskapp.pyc in __init__(self, import_name, settings, validator, data, auth, redis, url_converters, json_encoder, media, **kwargs)
158 self.settings = settings
159
--> 160 self.load_config()
161 self.validate_domain_struct()
162
C:\Users\***\Anaconda2\lib\site-packages\eve\flaskapp.pyc in load_config(self)
275
276 try:
--> 277 self.config.from_pyfile(pyfile)
278 except:
279 raise
C:\Users\***\Anaconda2\lib\site-packages\flask\config.pyc in from_pyfile(self, filename, silent)
128 try:
129 with open(filename, mode='rb') as config_file:
--> 130 exec(compile(config_file.read(), filename, 'exec'), d.__dict__)
131 except IOError as e:
132 if silent and e.errno in (
C:\Users\***\Anaconda2\lib\site-packages\bokeh\settings.py in <module>()
9 from os.path import join, abspath, isdir
10
---> 11 from .util.paths import ROOT_DIR, bokehjsdir
12
13
ValueError: Attempted relative import in non-package
I find that this problem occurs everytime I shutdown the system. I find that the I have to re-install eve and then this error occurs. Previously conda install <all packages> worked. But Since they've already been installed, becomes redundant on redoing.
How do I solve this problem for eternity?
This [link] suggests some solution that I didn't get...
So looking for clue regarding the same...
Any help is appreciated.
Related
I'm trying to use https://github.com/uber/orbit. I have the package installed without errors as far as I can see.
I can run everything just fine in my terminal on my mac. However, I load up vs-code and try and run there and I receive the error below. I can't figure out what the problem is or how to configure my vs-code to avoid this issue.
This causes the following error. NO issues in terminal.
from orbit.utils.dataset import load_iclaims
from orbit.models import DLT
from orbit.diagnostics.plot import plot_predicted_data
My python version is 3.9.15 that I am running this in both in terminal and in vs-code.
If anyone has an idea, can you please be specific on steps on how to fix this, as I have been hunting in vscode for a while and can't figure it out why I don't have this issue in terminal, but only in VSCODE
OperationalError Traceback (most recent call last)
Cell In[3], line 1
----> 1 from orbit.models import DLT
File ~/opt/anaconda3/lib/python3.9/site-packages/orbit/__init__.py:3
1 __all__ = ["satellite", "tle", "utilities"]
----> 3 from .satellite import satellite
File ~/opt/anaconda3/lib/python3.9/site-packages/orbit/satellite.py:3
1 from math import degrees
----> 3 from . import tle, utilities
5 class satellite:
6 def __init__(self,catnr):
File ~/opt/anaconda3/lib/python3.9/site-packages/orbit/tle.py:10
6 import ephem
8 from . import utilities
---> 10 requests_cache.install_cache(expire_after=86400)
12 def get(catnr):
13 page = html.fromstring(requests.get('http://www.celestrak.com/cgi-bin/TLE.pl?CATNR=%s' % catnr).text)
File ~/opt/anaconda3/lib/python3.9/site-packages/requests_cache/patcher.py:48, in install_cache(cache_name, backend, expire_after, urls_expire_after, allowable_codes, allowable_methods, filter_fn, stale_if_error, session_factory, **kwargs)
23 def install_cache(
24 cache_name: str = 'http_cache',
...
--> 168 self._local_context.con = sqlite3.connect(self.db_path, **self.connection_kwargs)
169 if self.fast_save:
170 self._local_context.con.execute('PRAGMA synchronous = 0;')
OperationalError: unable to open database file
There a requirement to rendering AutoCad DWG file in Python.
My first Question is,
1:- Is is possible to render/load dwg file in python and view the file/image in python environment?
2:- How can I do that? I tried using arcpy, but as it is a proprietary software of ArcGIS, it is not possible to directly import the library? What are the alternatives to that?
I even explored a lot of sources on the internet but not found anything useful.
Tried comtypes.client also for importing and viewing the same.
import array
import comtypes.client
acad = comtypes.client.GetActiveObject("AutoCAD.Application")
doc = acad.ActiveDocument
ms = doc.ModelSpace
doc.Import("sample.dwg", array.array('d', [0, 0, 0]), 1.0)
I am getting this error, I have downloaded AutoCAD software also still I am getting this error. Please suggest what I am missing and what is the error actually means.
OSError Traceback (most recent call last)
in
3 try:
----> 4 acad = comtypes.client.GetActiveObject("AutoCAD.Application")
5 except:
~\Anaconda3\envs\py36\lib\site-packages\comtypes\client_init_.py in GetActiveObject(progid, interface, dynamic)
172 """
--> 173 clsid = comtypes.GUID.from_progid(progid)
174 if dynamic:
~\Anaconda3\envs\py36\lib\site-packages\comtypes\GUID.py in from_progid(cls, progid)
77 inst = cls()
---> 78 _CLSIDFromProgID(str(progid), byref(inst))
79 return inst
_ctypes/callproc.c in GetResult()
OSError: [WinError -2147221005] Invalid class string
You can try something like this:
import comtypes.client
import time
try:
acad = comtypes.client.GetActiveObject("AutoCAD.Application")
except:
acad = comtypes.client.CreateObject("AutoCAD.Application")
while not acad.GetAcadState().IsQuiescent :
time.sleep(5)
acad.Visible = True
doc = acad.Documents.Open("C:\\Temp\\Sample.dwg")
I'm new to both python and OSX, so if i'm not understanding super basic stuff please forgive me.
I'm using python 2.7.12 on a fresh install from Homebrew. I also used Homebrew to install ipython, ffmpeg and libav (installs avconv, which I believe is required for what i'm trying to do).
I've used pip to install Scipy, numpy (which I think comes with scipy anyway?) and matplotlib
I'm running El Capitan v10.11.6
Background (for some context):
I'm running some hydrodynamic simulations that output a bunch of binary files. I wan't to stitch them together to create a movie. Lucky for me, one of my colleagues has already written a tidy little python script to do so (which he wrote in ipython).
Problem:
When trying to run
import matplotlib.animation
The script just hangs, and matplotlib animation never gets imported. I've tried changing the backend via
import matplotlib
matplotlib.use('tkagg')
import matplotlib.animaton
I've tried various backends that I got by running code from List of all available matplotlib backends
I have also tried import matplotlib.pyplot hangs (updating fc-lists)
Lastly, and i'm not sure if this is helpful, but leaving ipython trying to import matplot.animation for about 10 minutes, and then terminating it outputs the following
In [3]: import matplotlib.animation
^C---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-3-64e90e455a86> in <module>()
----> 1 import matplotlib.animation
/usr/local/lib/python2.7/site-packages/matplotlib/animation.py in <module>()
589
590 #writers.register('imagemagick')
--> 591 class ImageMagickWriter(MovieWriter, ImageMagickBase):
592 def _args(self):
593 return ([self.bin_path(),
/usr/local/lib/python2.7/site-packages/matplotlib/animation.py in wrapper(writerClass)
73 def register(self, name):
74 def wrapper(writerClass):
---> 75 if writerClass.isAvailable():
76 self.avail[name] = writerClass
77 return writerClass
/usr/local/lib/python2.7/site-packages/matplotlib/animation.py in isAvailable(cls)
284 stderr=subprocess.PIPE,
285 creationflags=subprocess_creation_flags)
--> 286 p.communicate()
287 return True
288 except OSError:
/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/subprocess.pyc in communicate(self, input)
798 return (stdout, stderr)
799
--> 800 return self._communicate(input)
801
802
/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.pyc in _communicate(self, input)
1417 stdout, stderr = self._communicate_with_poll(input)
1418 else:
-> 1419 stdout, stderr = self._communicate_with_select(input)
1420
1421 # All data exchanged. Translate lists into strings.
/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.pyc in _communicate_with_select(self, input)
1518 while read_set or write_set:
1519 try:
-> 1520 rlist, wlist, xlist = select.select(read_set, write_set, [])
1521 except select.error, e:
1522 if e.args[0] == errno.EINTR:
KeyboardInterrupt:
If you give any of this a second thought, even if you aren't able to help, thank you very much!
Do you have more than one version of Python installed? I would check your python path. Make sure matplotlib is in 2.7 in this case.
This might be relevant too -- import matplotlib.pyplot hangs
After I installed the package Iris with conda install -c scitools iris,
Whether using Ipython console or Jupyter notebook, the iris was always failed to import. The error subroutine shows like:
---------------------------------------------------------------------------
CalledProcessError Traceback (most recent call last)
<ipython-input-1-005053b25f37> in <module>()
----> 1 import iris
/Users/TEST/anaconda/lib/python2.7/site-packages/iris/__init__.pyc in <module>()
110 import iris.cube
111 import iris._constraints
--> 112 import iris.fileformats
113 import iris.io
114
/Users/TEST/anaconda/lib/python2.7/site-packages/iris/fileformats/__init__.py in <module>()
23 from six.moves import (filter, input, map, range, zip) # noqa
24
---> 25 from iris.io.format_picker import (FileExtension, FormatAgent,
26 FormatSpecification, MagicNumber,
27 UriProtocol, LeadingLine)
/Users/TEST/anaconda/lib/python2.7/site-packages/iris/io/__init__.py in <module>()
31
32 import iris.fileformats
---> 33 import iris.fileformats.dot
34 import iris.cube
35 import iris.exceptions
/Users/TEST/anaconda/lib/python2.7/site-packages/iris/fileformats/dot.py in <module>()
41 # Check PATH
42 subprocess.check_output([_DOT_EXECUTABLE_PATH, '-V'],
---> 43 stderr=subprocess.STDOUT)
44 except OSError:
45 _DOT_EXECUTABLE_PATH = None
/Users/TEST/anaconda/lib/python2.7/subprocess.pyc in check_output(*popenargs, **kwargs)
571 if cmd is None:
572 cmd = popenargs[0]
--> 573 raise CalledProcessError(retcode, cmd, output=output)
574 return output
575
CalledProcessError: Command '['dot', '-V']' returned non-zero exit status -5
I raised a similar issue on the iris GitHub tracker (https://github.com/SciTools/iris/issues/1899). Essentially, as much as I believe it was intended to be optional, the way it has been implemented I think Iris actually requires a dot installation. With conda, that should look like:
conda install graphviz
HTH
In my particular case, this error was resolved by installing GraphViz.
I believe the root case of this issue is that the graphiz python bindings cannot find the command line utilities required to render the output into some form, e.g. .pdf, .svg or .png.
I am new to iPython and trying to help another developer get started and we are both hitting same issues.
We are attempting to run a python unittest sample in iPython from https://docs.python.org/2/library/unittest.html#basic-example
The code runs just fine from command line on windows and ubuntu without ANY modifications
Exact same code from iPy notebook generates following exception:
AttributeError: 'module' object has no attribute '/home/myuser/'
The filename is: /home/myuser/example_unittest.ipynb
I have noodled the iPython docs and google with no luck as of the moment. Any debugging tips, or clues to solving this issue are appreciated.
(full stack):
AttributeError Traceback (most recent call last)
<ipython-input-2-39bc0ec16f11> in <module>()
28
29 if __name__ == '__main__':
---> 30 unittest.main()
31
/usr/lib/python2.7/unittest/main.pyc in __init__(self, module, defaultTest, argv, testRunner, testLoader, exit, verbosity, failfast, catchbreak, buffer)
92 self.testLoader = testLoader
93 self.progName = os.path.basename(argv[0])
---> 94 self.parseArgs(argv)
95 self.runTests()
96
/usr/lib/python2.7/unittest/main.pyc in parseArgs(self, argv)
147 else:
148 self.testNames = (self.defaultTest,)
--> 149 self.createTests()
150 except getopt.error, msg:
151 self.usageExit(msg)
/usr/lib/python2.7/unittest/main.pyc in createTests(self)
156 else:
157 self.test = self.testLoader.loadTestsFromNames(self.testNames,
--> 158 self.module)
159
160 def _do_discovery(self, argv, Loader=loader.TestLoader):
/usr/lib/python2.7/unittest/loader.pyc in loadTestsFromNames(self, names, module)
126 of string specifiers. See 'loadTestsFromName()'.
127 """
--> 128 suites = [self.loadTestsFromName(name, module) for name in names]
129 return self.suiteClass(suites)
130
/usr/lib/python2.7/unittest/loader.pyc in loadTestsFromName(self, name, module)
98 obj = module
99 for part in parts:
--> 100 parent, obj = obj, getattr(obj, part)
101
102 if isinstance(obj, types.ModuleType):
AttributeError: 'module' object has no attribute '/home/myuser/'
unittest.main() is primarily for command line execution.
In order to run a unittest in the ipython notebook, remove the if __name__ == '__main__' part of the code and, in a new cell, create a test suite and then run it using TextTestRunner,
suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
unittest.TextTestRunner().run(suite)
The reason you are getting that error because of unittest.main checks for arguments (sys.argv). It's what starts iPython or Jupyter.
Change your code to:
if __name__ == '__main__':
unittest.main(argv=['first-arg-is-ignored'], exit=False)
In the notebook, you will also want to include exit=False to prevent unittest.main from trying to shutdown the kernel process: