Mr D
Mr D

Reputation: 1

python path, can't use Django

i tried to install django, the installation was succeeded but i couldn't create new project. so i uninstalled and try to install again and this message showed up(didn't see it the first time):

WARNING: The script django-admin.exe is installed in 'C:\Users\ASUS\AppData\Roaming\Python\Python39\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

so i look up online and people said used sys.path.append to fix but when i used it:

sys.path.append('C:\Users\ASUS\AppData\Roaming\Python\Python39\Scripts')

following message appeared

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape. please help, i'm still new to Python and Django.

Upvotes: 0

Views: 1555

Answers (2)

AmineBTG
AmineBTG

Reputation: 697

You need to add 'C:\Users\ASUS\AppData\Roaming\Python\Python39\Scripts' to you system path. You can do it through Windows configurations or from the command line :

setx path "%path%;C:\Users\ASUS\AppData\Roaming\Python\Python39\Scripts"

Upvotes: 1

AKX
AKX

Reputation: 168967

Don't modify sys.path. It'll lead to pain and heartbreak and hard-to-debug issues. Wherever you made that edit, get rid of it. (The unicodeescape error message is due to you not using a r"" raw string, so \Users is interpreted as the start of an unicode sequence sers which is not a thing.) (In addition, editing sys.path within a Python script won't change your command prompt PATH, so there's no point in this anyway.)

Either:

  • as the message said, add C:\Users\ASUS\AppData\Roaming\Python\Python39\Scripts to your system PATH environment variable so you can use the globally-installed django-admin
  • directly run C:\Users\ASUS\AppData\Roaming\Python\Python39\Scripts\django-admin
  • or better yet, learn to create and use virtualenvs to keep your projects' dependencies separate; the virtualenv activation script will add the virtualenv's scripts directory to your path.

Upvotes: 1

Related Questions