简体   繁体   中英

PyCharm on Windows: 'django-admin' is not recognized as an internal or external command

When I try to install Django, PyCharm's Console shows me:

(my_env) C:\projects\app\web>pip install django==1.8.6
You are using pip version 7.1.0, however version 9.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip'    command.
Collecting django==1.8.6
Using cached Django-1.8.6-py2.py3-none-any.whl
Installing collected packages: django
Exception:
Traceback (most recent call last):
File "C:\projects\app\web\my_env\lib\site-packages\pip\basecommand.py", line 223, in main
status = self.run(options, args)
File "C:\projects\app\web\my_env\lib\site-packages\pip\commands\install.py", line 299, in run
root=options.root_path,
File "C:\projects\app\web\my_env\lib\site-packages\pip\req\req_set.py", line 646, in install
**kwargs
File "C:\projects\app\web\my_env\lib\site-packages\pip\req\req_install.py", line 813, in install
self.move_wheel_files(self.source_dir, root=root)
File "C:\projects\app\web\my_env\lib\site-packages\pip\req\req_install.py", line 1008, in move_wheel_files
isolated=self.isolated,
File "C:\projects\app\web\my_env\lib\site-packages\pip\wheel.py", line 479, in move_wheel_files
maker.make_multiple(['%s = %s' % kv for kv in console.items()])
File "C:\projects\app\web\my_env\lib\site-packages\pip\_vendor\distlib\scripts.py", line 334, in make_multiple
filenames.extend(self.make(specification, options))
File "C:\projects\app\web\my_env\lib\site-packages\pip\_vendor\distlib\scripts.py", line 323, in make
self._make_script(entry, filenames, options=options)
File "C:\projects\app\web\my_env\lib\site-packages\pip\_vendor\distlib\scripts.py", line 227, in _make_script
self._write_script(scriptnames, shebang, script, filenames, ext)
File "C:\projects\app\web\my_env\lib\site-packages\pip\_vendor\distlib\scripts.py", line 163, in _write_script
launcher = self._get_launcher('t')
File "C:\projects\app\web\my_env\lib\site-packages\pip\_vendor\distlib\scripts.py", line 302, in _get_launcher
result = finder(distlib_package).find(name).bytes
File "C:\projects\app\web\my_env\lib\site-packages\pip\_vendor\distlib\resources.py", line 297, in finder
raise DistlibException('Unable to locate finder for %r' % package)
pip._vendor.distlib.DistlibException: Unable to locate finder for 'pip._vendor.distlib'

But when I run pip freeze , it shows me:

(my_env) C:\projects\app\web>pip freeze
You are using pip version 7.1.0, however version 9.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Django==1.8.6
wheel==0.24.0

While I cannot start a Project:

(my_env) C:\projects\app\web>django-admin startproject mysite
'django-admin' is not recognized as an internal or external command,
operable program or batch file.

How can I fix this? I'm running PyCharm 2016 on Windows and Python 3.x.

Thank you,

You should be using virtual environments. (virtualenv) You need to activate your virtual environment before starting PyCharm, and you need to start PyCharm from the command prompt where your virtual environment is activated.

When you activate the virtualenv, it adds entries to the PATH for your shell (cmd) and any program launched from this shell inherits the PATH of the shell. By starting your editor within an activated virtualenv, it will find the right python and the right django-admin.

You can also execute the django-admin from the cmd prompt because of the activated environment.

You can read up on virtualenv to find the activate script that will put your cmd prompt in the right frame of mind for all of this to work.

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