0

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.

3
  • \ are used to escape stuff in strings in python, hence you need to escape them too: sys.path.append('C:\\Users\\ASUS\\AppData\\Roaming\\Python\\Python39\\Scripts'), note instead of using that just set your environment variables and add it to the path there Commented Jun 7, 2021 at 8:08
  • @AbdulAzizBarkat Or use a raw string: r"C:\Users..." – however, modifying sys.path in the first place is a bad idea. Commented Jun 7, 2021 at 8:10
  • @AKX edited just before your comment ;) Commented Jun 7, 2021 at 8:10

2 Answers 2

1

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.
Sign up to request clarification or add additional context in comments.

Comments

1

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"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.