Using sockjs with Tornado. On server run, this is the trace returned :
python server.py
Traceback (most recent call last):
File "server.py", line 10, in <module>
from sockjs.tornado import SockJSRouter
File "/Users/mohit/anaconda/envs/py34/lib/python3.4/site-packages/sockjs/__init__.py", line 20, in <module>
from sockjs.route import get_manager, add_endpoint
File "/Users/mohit/anaconda/envs/py34/lib/python3.4/site-packages/sockjs/route.py", line 11, in <module>
from sockjs.transports import handlers
File "/Users/mohit/anaconda/envs/py34/lib/python3.4/site-packages/sockjs/transports/__init__.py", line 3, in <module>
from .jsonp import JSONPolling
File "/Users/mohit/anaconda/envs/py34/lib/python3.4/site-packages/sockjs/transports/jsonp.py", line 8, in <module>
from .base import StreamingTransport
File "/Users/mohit/anaconda/envs/py34/lib/python3.4/site-packages/sockjs/transports/base.py", line 2, in <module>
from aiohttp import errors
ImportError: cannot import name 'errors'
I would recommend you to upgrade python version to
Python 3.5+ and utilize PEP-492 aka async/await. If you are using Python 3.4 please replace await with yield from and async def with #coroutine e.g.:
async def coro(...):
ret = await f()
should be replaced by:
#asyncio.coroutine
def coro(...):
ret = yield from f()
from aiohttp documentaion:
Dependencies
Python 3.4.2+
chardet, multidict, async_timeout, yarl
Optionally you may install the cChardet and aiodns libraries (highly recommended for sake of speed).
$ pip install cchardet
$ pip install aiodns
Related
My use case is that I am trying to write my dataframe to S3 bucket for which I installed s3fs==2015.5.0 using pip3. Now when I run the code
import s3fs
def my_func():
# my logic
my_func()
It returns the following error:
Traceback (most recent call last):
File "main.py", line 1, in <module>
import s3fs
File "/usr/local/lib/python3.7/dist-packages/s3fs/__init__.py", line 1, in <module>
from .core import S3FileSystem, S3File
File "/usr/local/lib/python3.7/dist-packages/s3fs/core.py", line 14, in <module>
import aiobotocore
File "/usr/local/lib/python3.7/dist-packages/aiobotocore/__init__.py", line 11, in <module>
from .session import get_session, AioSession
File "/usr/local/lib/python3.7/dist-packages/aiobotocore/session.py", line 6, in <module>
from .client import AioClientCreator, AioBaseClient
File "/usr/local/lib/python3.7/dist-packages/aiobotocore/client.py", line 11, in <module>
from .args import AioClientArgsCreator
File "/usr/local/lib/python3.7/dist-packages/aiobotocore/args.py", line 8, in <module>
from .endpoint import AioEndpointCreator
File "/usr/local/lib/python3.7/dist-packages/aiobotocore/endpoint.py", line 12, in <module>
from aiobotocore.httpsession import AIOHTTPSession
File "/usr/local/lib/python3.7/dist-packages/aiobotocore/httpsession.py", line 12, in <module>
from botocore.httpsession import ProxyConfiguration, create_urllib3_context, \
ImportError: cannot import name 'InvalidProxiesConfigError' from 'botocore.httpsession' (/usr/local/lib/python3.7/dist-packages/botocore/httpsession.py)
My requirements.txt file something like this:
boto3==1.18.65
s3fs==2021.5.0
fastparquet==0.7.1
pip3 install -r requirements.txt install the packages but also returns
aiobotocore 1.4.2 requires botocore<1.20.107,>=1.20.106, but you'll have botocore 1.19.28 which is incompatible.
s3fs 2021.5.0 requires fsspec==2021.05.0, but you'll have fsspec 2021.10.1 which is incompatible.
For some reason it just started to happen now. I was using the similar packages earlier and it was working fine. Any ideas why it is not working now?
I want to install flask_dance using pip3 but everytime i am getting this error:
ImportError: cannot import name 'dist'
my traceback looks something like this:
Traceback (most recent call last):
File "/home/kishori/bookverm/alpha/bin/pip3", line 7, in <module>
from pip import main
File "/home/kishori/bookverm/alpha/lib/python3.6/site-packages/pip/__init__.py", line 29, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/home/kishori/bookverm/alpha/lib/python3.6/site-packages/pip/utils/__init__.py", line 23, in <module>
from pip.locations import (
File "/home/kishori/bookverm/alpha/lib/python3.6/site-packages/pip/locations.py", line 9, in <module>
from distutils import sysconfig
File "/home/kishori/bookverm/alpha/lib/python3.6/distutils/__init__.py", line 25, in <module>
from distutils import dist, sysconfig
ImportError: cannot import name 'dist'
I have used cx-freeze to make an executable file from my python 3 script. The issue is that apparently cx-freeze is having a hard time importing scipy scripts. I had to resolve other issues previously, e.g. adding the tcl library files manually. Anyway, my setup files is below:
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\\Gobryas\\AppData\\Local\\Continuum\\anaconda3\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\Gobryas\\AppData\\Local\\Continuum\\anaconda3\\tcl\\tk8.6"
additional_mods = ['numpy.core._methods', 'numpy.lib.format']
setup(name = "Curve Characterization" ,
options = {'build_exe': {'includes': additional_mods}},
version = "0.1" ,
description = "" ,
executables = [Executable("curvCharLite.py")])
This is the error that I get:
ImportError: cannot import name '_ni_support'
Full details
Traceback (most recent call last):
File "C:\Users\Gobryas\AppData\Local\Continuum\anaconda3\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
File "C:\Users\Gobryas\AppData\Local\Continuum\anaconda3\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
exec(code, m.__dict__)
File "curvCharLite.py", line 21, in <module>
File "c:\users\Gobryas\documents\mo\project 1\ruptures\ruptures\__init__.py", line 8, in <module>
from .detection import (Binseg, BottomUp, Dynp, Omp, OmpK, Pelt, Window,
File "c:\users\Gobryas\documents\mo\project 1\ruptures\ruptures\detection\__init__.py", line 51, in <module>
from .window import Window
File "c:\users\Gobryas\documents\mo\project 1\ruptures\ruptures\detection\window.py", line 112, in <module>
from scipy.signal import argrelmax
File "C:\Users\Gobryas\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\signal\__init__.py", line 311, in <module>
from ._savitzky_golay import savgol_coeffs, savgol_filter
File "C:\Users\Gobryas\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\signal\_savitzky_golay.py", line 6, in <module>
from scipy.ndimage import convolve1d
File "C:\Users\Gobryas\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\ndimage\__init__.py", line 161, in <module>
from .filters import *
File "C:\Users\Gobryas\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\ndimage\filters.py", line 35, in <module>
from . import _ni_support
ImportError: cannot import name '_ni_support'
PS 1: There is a similar issue asked here, but no helpful answer really.
PS 2: I'm using scipy 1.1.0, cx-freeze 5.1.1, and python 3.6.5
So, I think I found a solution for this problem inspired by the post by #fepzzz.
Looks like there are bad conflicts between cx-freeze and scipy which can be avoided as follows. I needed to modify the include_files build option as below:
import os
import scipy
includefiles_list=[]
scipy_path = os.path.dirname(scipy.__file__)
includefiles_list.append(scipy_path)
build_options = dict(packages=['matplotlib'], #this line solves an issue w/ matplotlib
include_files=includefiles_list, #this line is for scipy issue
includes=['matplotlib.backends.backend_qt5agg']) #this line solves another issue w/ matplotlib
Hope this helps others.
This works:
import os
import sys
with open('tests.py') as fptr:
script_content = fptr.read()
exec(script_content)
And this not:
def run():
import os
import sys
with open('tests.py') as fptr:
script_content = fptr.read()
exec(script_content)
run()
Result:
Traceback (most recent call last):
File "tmp.py", line 8, in <module>
run()
File "tmp.py", line 6, in run
exec(script_content)
File "<string>", line 15, in <module>
File "<string>", line 16, in PlaceSpitter
NameError: name 'Place' is not defined
Could anyone tell my why and how to fix it?
I've read again - carrefully - python's docs especially this one:
Remember that at module level, globals and locals are the same dictionary
And try this:
def run():
import os
import sys
with open('tests.py') as fptr:
script_content = fptr.read()
exec(script_content, globals())
run()
which now works!
I still don't know why but now at least it works.
I want to use Numpy in Cython, but encountered the following error. This error happens even if I run the simple code, so it should be an issue related to importing Numpy.
My environment:
OS X Yosemite
Python 3.4.3
setup.py:
import numpy as np
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = 'my_code',
ext_modules = cythonize('my_code.pyx'),
include_path = [numpy.get_include()]
)
my_code.pyx:
cimport numpy as np
cdef int a
Execute in Terminal:
$ python3 setup.py build_ext --inplace
Traceback (most recent call last):
File "/Users/***/setup.py", line 1, in <module>
import numpy as np
File "/usr/local/lib/python3.4/site-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/local/lib/python3.4/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python3.4/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/local/lib/python3.4/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python3.4/site-packages/numpy/core/__init__.py", line 58, in <module>
from numpy.testing import Tester
File "/usr/local/lib/python3.4/site-packages/numpy/testing/__init__.py", line 10, in <module>
from unittest import TestCase
File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/__init__.py", line 59, in <module>
from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/case.py", line 253, in <module>
class _CapturingHandler(logging.Handler):
AttributeError: 'module' object has no attribute 'Handler'
Old question but I ran into this because I had a very similar issue with numpy.
It turns out I had a directory named logging as a sibling of the script I was trying to run. So the problem was a simple naming collision between my local project folder and the logging module numpy expected to find. Renaming the project logging folder solved the issue for me.
Looking at OP's error message, I suspect this was the case for them as well.