简体   繁体   中英

Can't import os in python

I get this message when trying to import os while using Pyzo 4.10.2 :

ValueError: source code string cannot contain null bytes

Here is the code I tried :

from os import *
os.mkdir('Repertoire_test')

I also tried import os previously.

When I try it in python directly (the black background interpreter) it works though, as i can see the folder in my hard drive :


Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.mkdir('Rpertoire_test')
>>> 

Thanks you

One solution may be changing

from os import *

to

import os

If this doesn't work I would try reinstalling python

if the error is coming from your conda, it's certainly because the environment is not activated, try:

conda update conda
activate base

restart your working station then:

conda activate (environment name)

if the error persists try the previous steps preceded by:

sudo -s 

Is this your actual code? Cause this should cause another error as you are importing everything from os with * but trying to access with os.foo(). This should cause an NameError (I guess). Try:

import os   
os.mkdir('Repertoire_test')

After correcting this try another editor/IDE. The error indicates that somewhere in your code there is an invalid character wich is not displayed and your IDE does not get this. Or copy the code into a gedit/notepad etc. and try again

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM