Python - ValueError: source code string cannot contain null bytes - python

I have a problem. I am using Windows 7 32x, Python 3.
When I try to import the numpy library in code, no matter what, I get an error. I don't remember how to solve it.
The code itself:
import numba
print('Hello World!')
And here is the error:
Traceback (most recent call last):
File "C:\Users\User\Desktop\numba_test.py", line 1, in <module>
import numba
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\__init__.py", line 38, in <module>
from numba.core.decorators import (cfunc, generated_jit, jit, njit, stencil,
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\core\decorators.py", line 12, in <module>
from numba.stencils.stencil import stencil
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\stencils\stencil.py", line 11, in <module>
from numba.core import types, typing, utils, ir, config, ir_utils, registry
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\core\registry.py", line 4, in <module>
from numba.core import utils, typing, dispatcher, cpu
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\core\dispatcher.py", line 13, in <module>
from numba.core import (
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\core\compiler.py", line 6, in <module>
from numba.core import (utils, errors, typing, interpreter, bytecode, postproc,
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\core\cpu.py", line 15, in <module>
import numba.core.entrypoints
File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\numba\core\entrypoints.py", line 8, in <module>
import importlib_metadata
ValueError: source code string cannot contain null bytes
I have reinstalled numba several times, searched for solutions on the Internet, but all without success. Help what you can.

import numbers
print('Hello World!')

Related

Whenever I run my discord bot using discord.py I'm getting an AttributeError 'logging' has no attribute 'getlogger'

All my code is on github except for the token.py file for obvious reasons.
bot.py file
I have had similar issues in the past and have resolved them by reconstructing some code so I apologize in advance if this is another one of those issues where I missed a capital or something but I have tried all the obvious syntax issues and none of them seemed to work. Atom also didn't show any errors.
Here is the whole error message:
Traceback (most recent call last):
File "C:\Users\james\Documents\botpy\bot.py", line 5, in <module>
import discord
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\__init__.py", line 21, in <module>
import logging
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\logging\__init__.py", line 26, in <module>
import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\linecache.py", line 11, in <module>
import tokenize
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\tokenize.py", line 34, in <module>
from token import *
File "C:\Users\james\Documents\botpy\token.py", line 2, in <module>
from discord.ext import commands
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\__init__.py", line 13, in <module>
from .bot import Bot, AutoShardedBot, when_mentioned, when_mentioned_or
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 27, in <module>
import asyncio
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\asyncio\__init__.py", line 8, in <module>
from .base_events import *
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 18, in <module>
import concurrent.futures
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\concurrent\futures\__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\concurrent\futures\_base.py", line 42, in <module>
LOGGER = logging.getLogger("concurrent.futures")
AttributeError: partially initialized module 'logging' has no attribute 'getLogger' (most likely due to a circular import)
Try to rename your file into main.py
I had a similar error just because the filename.

Mac system generate error message when I call python script on terminal

My code is simply the follow and work few days ago:
import pandas as pd
df = pd.read_csv('WORLDBANK-ZAF_MYS_PROP_4044_SEC_MF.csv')
print(df.head())
But now whenever I try to run it by calling python my_io.py on my Mac terminal it generates the following messages:
Bases-MacBook-Pro:data_analysis me$ python my_io.py
Traceback (most recent call last):
File "my_io.py", line 1, in
import pandas as pd
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/init.py", line 13, in
import(dependency)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/init.py", line 142, in
from . import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/init.py", line 8, in
from .type_check import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/init.py", line 72, in
from numpy.testing.nosetester import _numpy_tester
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/init.py", line 12, in
from . import decorators as dec
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/decorators.py", line 20, in
from .utils import SkipTest, assert_warns
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in
from tempfile import mkdtemp, mkstemp
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in
import io as _io
File "/Users/gongzhuli/Desktop/data_analysis/io.py", line 3, in
AttributeError: 'module' object has no attribute 'read_csv'
Can someone please help me, I have no idea what is going on here..
Your file is called io.py, which is a library module to handle file-like buffers among other things.
pandas imports tempfile which needs it:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
import io as _io
and your filename gets in the way of the import chain and prevents import from going through.
Just rename your file with something more specific (like my_io.py for instance?)

Theano tensor import error

I have been trying to import theano.tensor in my code.
I have used theano.tensor before. All of my previous code importing theano.tensor works perfectly in my machine. Now I am trying to write another script importing the tensor from theano and I am getting the following exception.
Traceback (most recent call last):
File "code.py", line 2, in <module>
import theano.tensor as T
File "/anaconda3/lib/python3.5/site-packages/theano/__init__.py", line 52, in <module>
from theano.gof import (
File "/anaconda3/lib/python3.5/site-packages/theano/gof/__init__.py", line 56, in <module>
from theano.gof.opt import (
File "/anaconda3/lib/python3.5/site-packages/theano/gof/opt.py", line 11, in <module>
import pdb
File "/anaconda3/lib/python3.5/pdb.py", line 75, in <module>
import code
File "/localtmp/saikat/CovInfo/Closure/code.py", line 2, in <module>
import theano.tensor as T
File "/anaconda3/lib/python3.5/site-packages/theano/tensor/__init__.py", line 6, in <module>
from theano.tensor.basic import *
File "/anaconda3/lib/python3.5/site-packages/theano/tensor/basic.py", line 17, in <module>
from theano.tensor import elemwise
File "/anaconda3/lib/python3.5/site-packages/theano/tensor/elemwise.py", line 13, in <module>
from theano import scalar
File "/anaconda3/lib/python3.5/site-packages/theano/scalar/__init__.py", line 2, in <module>
from .basic import *
File "/anaconda3/lib/python3.5/site-packages/theano/scalar/basic.py", line 25, in <module>
from theano import gof, printing
File "/anaconda3/lib/python3.5/site-packages/theano/printing.py", line 22, in <module>
from theano.compile import Function, debugmode, SharedVariable
File "/anaconda3/lib/python3.5/site-packages/theano/compile/__init__.py", line 9, in <module>
from theano.compile.function_module import *
File "/anaconda3/lib/python3.5/site-packages/theano/compile/function_module.py", line 22, in <module>
import theano.compile.mode
File "/anaconda3/lib/python3.5/site-packages/theano/compile/mode.py", line 77, in <module>
OPT_NONE = gof.Query(include=[], exclude=exclude)
AttributeError: module 'theano.gof' has no attribute 'Query'
I cannot find any plausible reason for this exception.
I guess i got your problem. See in the error log:
File "/anaconda3/lib/python3.5/pdb.py", line 75, in <module>
import code
I believe there is another script called code.py in Theano which gets called from pdb.py when python interpreter executes your script which is also named as code.py. I am guessing python interpreter is mixing up these two scripts and executing the wrong one! You can change the filename and check whether the error disappear or not.

Python 2.6 -- paramiko import error

I have some scripts that run every 30 minutes in cron that import paramiko. Seemingly at random, I will get one of these two errors during import:
Traceback (most recent call last):
...
File "build/bdist.linux-x86_64/egg/paramiko/__init__.py", line 65, in <module>
File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 42, in <module>
File "build/bdist.linux-x86_64/egg/paramiko/packet.py", line 39, in <module>
File "build/bdist.linux-x86_64/egg/Crypto/Hash/HMAC.py", line 66, in <module>
File "build/bdist.linux-x86_64/egg/Crypto/Util/strxor.py", line 7, in <module>
File "build/bdist.linux-x86_64/egg/Crypto/Util/strxor.py", line 6, in __bootstrap__
ImportError: dynamic module does not define init function (initstrxor)
-- OR --
Traceback (most recent call last):
...
File "build/bdist.linux-x86_64/egg/paramiko/__init__.py", line 65, in <module>
File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 53, in <module>
File "build/bdist.linux-x86_64/egg/Crypto/Cipher/ARC4.py", line 66, in <module>
File "build/bdist.linux-x86_64/egg/Crypto/Cipher/_ARC4.py", line 7, in <module>
File "build/bdist.linux-x86_64/egg/Crypto/Cipher/_ARC4.py", line 6, in __bootstrap__
ImportError: dynamic module does not define init function (init_ARC4)
Every time that I have seen this issue, simply rerunning the script allows paramiko to import correctly and the script to finish.
What can cause this issue? Any help is greatly appreciated.
While I have no idea what may be causing the error, it seems it's failing on the native parts of pycrypto, so you may want to retry a couple of times:
from time import sleep
n_tries= 3
import_success= False
while not import_success:
try:
from Crypto.Cipher import Blowfish, AES, DES3, ARC4
from Crypto.Hash import MD5, SHA, SHA256, HMAC
from Crypto import Random
from Crypto.PublicKey import DSA, RSA
from Crypto.Util import Counter, number
import_success= True
except ImportError:
if not n_tries:
raise #re-raise ImportError
n_tries-=1
sleep(1)

Error while importing SQLObject on Windows

I am getting following error while importing SQLObject on Window. Does anyone knows what is this error about and how to solve it?
==============================
from sqlobject import *
File "c:\python26\lib\site-packages\sqlobject-0.10.4-py2.6.egg\sqlobject\__init__.py", line 5, in <module>
from main import *
File "c:\python26\lib\site-packages\sqlobject-0.10.4-py2.6.egg\sqlobject\main.py", line 32, in <module>
import dbconnection
File "c:\python26\lib\site-packages\sqlobject-0.10.4-py2.6.egg\sqlobject\dbconnection.py", line 17, in <module>
from joins import sorter
File "c:\python26\lib\site-packages\sqlobject-0.10.4-py2.6.egg\sqlobject\joins.py", line 5, in <module>
import events
File "c:\python26\lib\site-packages\sqlobject-0.10.4-py2.6.egg\sqlobject\events.py", line 3, in <module>
from sqlobject.include.pydispatch import dispatcher
File "c:\python26\lib\site-packages\sqlobject-0.10.4-py2.6.egg\sqlobject\include\pydispatch\dispatcher.py", line 30, in <module>
import saferef, robustapply, errors
EOFError: EOF read where object expected
Looks like your c:\python26\lib\site-packages\sqlobject-0.10.4-py2.6.egg file may be truncated or otherwise damaged. How does it compare to a freshly downloaded one (in terms of both length and checksum)?

Categories

Resources