Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'causing': 0.04; 'argument': 0.05; 'much!': 0.05; '<>,': 0.07; 'debug': 0.07; 'modifying': 0.07; 'nicely': 0.07; 'none,': 0.07; 'skip:` 10': 0.07; 'sys': 0.07; 'here?': 0.09; 'literal': 0.09; 'throws': 0.09; 'to)': 0.09; 'url:github': 0.09; 'wrong,': 0.09; 'python': 0.11; 'def': 0.12; 'changes': 0.15; 'posted': 0.15; '__init__.py': 0.16; 'ah,': 0.16; 'builtins': 0.16; 'fine.': 0.16; 'hack,': 0.16; 'hits': 0.16; 'numpy': 0.16; 'obviously,': 0.16; 'skip:" 100': 0.16; 'str,': 0.16; 'subject:import': 0.16; 'travis': 0.16; 'typeerror:': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'module': 0.19; "skip:' 30": 0.19; 'written': 0.21; 'seems': 0.21; '>>>': 0.22; 'import': 0.22; 'mike': 0.22; 'error': 0.23; 'bytes': 0.24; 'instead.': 0.24; 'received:65.55.116': 0.24; 'skip:` 20': 0.24; 'mon,': 0.24; "haven't": 0.24; 'looks': 0.24; 'question': 0.24; "i've": 0.25; 'extension': 0.26; 'suggested': 0.26; 'this:': 0.26; '(for': 0.26; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'tried': 0.27; 'function': 0.29; 'skip:- 40': 0.29; "doesn't": 0.30; 'errors': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'work.': 0.31; 'gives': 0.31; "skip:' 10": 0.31; '"",': 0.31; '3.x': 0.31; '>>>>': 0.31; 'clever': 0.31; 'yes.': 0.31; 'file': 0.32; 'there.': 0.32; 'url:python': 0.33; '(most': 0.33; 'copying': 0.34; 'date:': 0.34; 'subject:with': 0.35; "can't": 0.35; 'anywhere': 0.35; 'something': 0.35; 'but': 0.35; 'really': 0.36; 'subject:Simple': 0.36; 'url:listinfo': 0.36; "didn't": 0.36; 'thanks': 0.36; 'url:org': 0.36; 'wrong': 0.37; 'email addr:python.org': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'track': 0.38; 'anything': 0.39; 'recent': 0.39; 'subject:': 0.39; 'skip:. 10': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'url:mail': 0.40; 'simple': 0.61; 'back': 0.62; 'email addr:gmail.com': 0.63; 're:': 0.63; 'skip:n 10': 0.64; 'great': 0.65; 'email name:python-list': 0.65; 'laptop': 0.65; 'to:addr:gmail.com': 0.65; 'within': 0.65; 'here': 0.66; '20,': 0.68; 'line,': 0.68; 'gotten': 0.74; 'goals': 0.81; 'c-api': 0.84; 'complaint': 0.84; 'hands': 0.96 X-TMN: [wd3lkQWBY5VPeBsHKYDnwhOXZwu0yGhD] X-Originating-Email: [moboyle79@outlook.com] From: Mike Boyle To: Ian Kelly , Python Subject: RE: Simple import in python 3 errors with complaint about bytes Date: Tue, 21 Oct 2014 00:20:54 +0000 Importance: Normal In-Reply-To: References: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 21 Oct 2014 00:20:55.0503 (UTC) FILETIME=[E1520DF0:01CFECC4] X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 90 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413850925 news.xs4all.nl 2870 [2001:888:2000:d::a6]:46886 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79358 Ah=2C yes. =A0Thanks to that clever import debug hack=2C and the suggestion= that it would actually be an import within the module causing the trouble= =2C I managed to track it down. =A0I had tried copying some py3k changes fr= om the "rational" module in numpy/numpy-dtypes=2C but evidently didn't do i= t right=2C or it just doesn't work. =A0I was using `PyImport_Import` with a= PyString. =A0Now=2C going back to the original `PyImport_ImportModule` wit= h a literal `char*`=2C everything seems to work great (for me at least=3B T= ravis isn't so sure...).=0A= =0A= Thanks very much!=0A= =0A= =0A= =0A= =0A= ----------------------------------------=0A= > From: ian.g.kelly@gmail.com=0A= > Date: Mon=2C 20 Oct 2014 17:48:23 -0600=0A= > Subject: Re: Simple import in python 3 errors with complaint about bytes= =0A= > To: python-list@python.org=0A= >=0A= > On Mon=2C Oct 20=2C 2014 at 5:29 PM=2C Mike Boyle = wrote:=0A= >> I'm modifying an extension written with the c-api to have a datatype of = quaternions =2C with one of the = goals being python 3 support. It works nicely in python 2.7=2C but for pyth= on 3.x gives an error that I can't find anywhere on the google. The directo= ry looks like this:=0A= >>=0A= >> .../site-packages/=0A= >> quaternion/=0A= >> __init__.py=0A= >> numpy_quaternion.so=0A= >>=0A= >> __init__.py contains a line like this:=0A= >>=0A= >> from .numpy_quaternion import quaternion=0A= >>=0A= >> But when it hits that line=2C python 3 throws its hands up in disgust:= =0A= >>=0A= >>> python -c 'import quaternion'=0A= >> Traceback (most recent call last):=0A= >> File ""=2C line 1=2C in =0A= >> File "/Users/mynamehere/.continuum/anaconda/envs/py3k/lib/python3.4/site= -packages/quaternion/__init__.py"=2C line 3=2C in =0A= >> from .numpy_quaternion import quaternion=0A= >> TypeError: __import__() argument 1 must be str=2C not bytes=0A= >>=0A= >> The only thing before that line is `import numpy as np`=2C which typical= ly works just fine. Obviously=2C I'm using python3.4 to compile and (attemp= t to) import (with a conda environment)=2C so it's not something as dumb as= using the wrong python. Also=2C this is the result for both me on my lapto= p and Travis-CI =2C so it doe= sn't seem to be anything peculiar to my installation. I've posted this ques= tion on stackoverflow=2C but haven't gotten much interest=3B the only respo= nder suggested I ask here instead.=0A= >>=0A= >> Any ideas what's going wrong=2C or where I can go from here?=0A= >=0A= > I question whether the error is really coming from that particular=0A= > import line. Try shadowing the __import__ function to see what's=0A= > actually being passed there. E.g.:=0A= >=0A= >>>> orig_import =3D __import__=0A= >>>> def debug_import(name=2C globals=3DNone=2C locals=3DNone=2C fromlist= =3D()=2C level=3D0):=0A= > ... print("debug_import:"=2C name=2C globals=2C locals=2C fromlist=2C lev= el)=0A= > ... return orig_import(name=2C globals=2C locals=2C fromlist=2C level)=0A= > ...=0A= >>>> import builtins=0A= >>>> builtins.__import__ =3D debug_import=0A= >>>> import sys=0A= > debug_import: sys {'__spec__': None=2C '__loader__': '_frozen_importlib.BuiltinImporter'>=2C '__package__': None=2C 'builtins'= :=0A= > =2C 'orig_import': __import__>=2C '__builtins__': =2C=0A= > '__name__': '__main__'=2C '__doc__': None=2C 'debug_import': debug_import at 0x7f6096aac9d8>} {'__spec__': None=2C '__loader__':=0A= > =2C '__package__': None=2C=0A= > 'builtins': =2C 'orig_import': function __import__>=2C '__builtins__': =2C= =0A= > '__name__': '__main__'=2C '__doc__': None=2C 'debug_import': debug_import at 0x7f6096aac9d8>} None 0=0A= > --=0A= > https://mail.python.org/mailman/listinfo/python-list=0A= =