Jonathan Balde
Jonathan Balde

Reputation: 3

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

Upvotes: 0

Views: 3531

Answers (3)

Nicklas Bocksberger
Nicklas Bocksberger

Reputation: 121

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

Upvotes: 0

Nebula-II
Nebula-II

Reputation: 1

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 

Upvotes: 0

Supergamer5465
Supergamer5465

Reputation: 77

One solution may be changing

from os import *

to

import os

If this doesn't work I would try reinstalling python

Upvotes: 0

Related Questions