简体   繁体   English

如何使用virtualenv在django中启动一个新项目

[英]How to start a new project in django using virtualenv

I just installed virtualenv and in it I installed django. 我刚刚安装了virtualenv,并在其中安装了django。 However, when I go to the django-admin terminal in the bin file, I wrote 但是,当我去bin文件中的django-admin终端时,我写道

django-admin startproject mysite 

I thought that would start a new project but it just returned 我认为这将启动一个新项目,但它刚刚回来

Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.). 请注意,仅列出Django核心命令,因为未正确配置设置(错误:请求设置INSTALLED_APPS,但未配置设置。您必须在访问设置之前定义环境变量DJANGO_SETTINGS_MODULE或调用settings.configure()。)。

Here is how to start a new django project in a virtualenv : 以下是如何在virtualenv中启动一个新的django项目

1 . 1 Create a new virtualenv for your project: 为您的项目创建一个新的virtualenv:

virtualenv py_env --python=python3

--python=python3 is not mandatory. --python=python3不是必需的。 I'd recommend programming in python3.x but this is up to you. 我建议在python3.x中编程,但这取决于你。 If you are unsure about what is the default python that will be used when omitting the --python option, type python -V in your terminal. 如果您不确定在省略--python选项时将使用的默认python是什么,请在终端中键入python -V

2 . 2 Activate the virtualenv: 激活virtualenv:

source py_env/bin/activate

If you see a (py_env) at the beginning of the command line, then you know the virtualenv is activated. 如果在命令行的开头看到(py_env) ,那么就知道virtualenv已激活。 To deactivate, simply type deactivate . 要取消激活,只需键入deactivate

3 . 3 Install the required packages: 安装所需的包:

pip install django

While this is not needed, I recommend using ipython , so you might want to run pip install ipython . 虽然这不是必需的,但我建议使用ipython ,因此您可能希望运行pip install ipython

4 . 4 Create a new django project: 创建一个新的django项目:

django-admin startproject mysite

Hope that helped and happy coding! 希望有帮助和快乐的编码!

I think you should first make a virtual environment: 我认为你应该首先创建一个虚拟环境:

pip3 install --user pipenv pip3 install --user pipenv

Make a virtual environment: 创建一个虚拟环境:

pipenv --python 3.6 pipenv --python 3.6

Activate the environment: 激活环境:

pipenv shell pipenv shell

and after this do whatever you want i think it would work better now 并且在此之后做任何你想做的事情我认为它现在会更好

Pipenv is best to use because it brings the best Packages of python so that there may not be further bugs while making the virtual environment. Pipenv是最好用的,因为它带来了最好的python包,这样在创建虚拟环境时可能不会有进一步的bug。 And django can be replicated properly. django可以正确复制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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