无法安装Django(或设置虚拟环境)

时间:2016-11-26 03:21:13

标签: python django python-3.x pip virtualenv

我是初学网络程序员,我正在尝试开始学习Python上的Web应用程序开发。我有Python 3.4,我使用的是Windows 10.使用pygame模块制作游戏时Python工作正常。最近,我想尝试使用web dev,因此我尝试安装Django(以及创建虚拟环境),这两种方式都没能成功。

我已经安装了pip,如下图所示。

Pip installed

但出于某些原因,当我进入命令提示符时:

'$' is not recognized as an internal or external command, operable program or batch file.

我明白了:

C:\Users\Steven\>pip install django

OR

'pip' is not recognized as an internal or external command, operable program, or batch file.

我明白了:

int main()
{
    ofstream log;
    log.open("Log.txt");
    int MAX_NUM = 100;
    BankAccount account[MAX_NUM];
    int num_accts = 0;
    char selection = 'Z';
    cout << "How many accounts are there?" << endl;
    log << "How many accounts are there?" << endl;
    cin >> MAX_NUM;
    read_accts(account, MAX_NUM, num_accts);
    cout << endl;
    cout << "There are " << num_accts << " accounts" << endl;
    log << "There are " << num_accts << " accounts" << endl;
    cout << endl;
    print_accts(account, MAX_NUM);
    cout << endl;
    `

    while (selection != 'Q' && selection != 'q')
    {

        menu();
        cin >> selection;
        log << selection;
        switch (selection)
        {
            case 'W':
                case 'w':
                withdrawal(account, num_accts);
                break;
            case 'D':
                case 'd':
                deposit(account, num_accts);
                break;
            case 'N':
                case 'n':
                new_acct(account, num_accts);
                break;
            case 'B':
                case 'b':
                balance(account, num_accts);
                break;
            case 'I':
                case 'i':
                account_info(account, num_accts);
                break;
            case 'C':
                case 'c':
                close_acct(account, num_accts);
                break;
            case 'Q':
                case 'q':
                print_accts(account, num_accts);
                break;
            default:
                cout << "Invalid selection" << endl;
                log << "Invalid selection" << endl;

        }
        cout << endl;
    }
    print_accts(account, MAX_NUM);
    cout << "Goodbye" << endl;
    log.close();
    return 0;
}

int read_accts(BankAccount account[], int MAX_NUM, int &num_accts)
{
    ofstream log;
    log.open("log.txt", std::ofstream::app);
    string f;
    string l;
    int social;
    int acct;
    string type;
    double bal;
    int i = 0;
    ifstream readfile;
    readfile.open("bankdatain.txt");
    if (!readfile)
    {
        cout << "Can't open input file." << endl;
        log << "Can't open input file." << endl;
        exit(1);
    }
    while (readfile >> f >> l >> social >> acct >> type >> bal)
    {
        account[i].setfname(f);
        account[i].setlname(l);
        account[i].setssnum(social);
        account[i].setacctnum(acct);
        account[i].settype(type);
        account[i].setbalance(bal);
        i++;
        num_accts++;
    }

    return num_accts;
}

void menu()
{
    ofstream log;
    log.open("Log.txt");
    cout << "W - Withdrawal" << endl;
    log << "W - Withdrawal" << endl;
    cout << "D - Deposit" << endl;
    log << "D - Deposit" << endl;
    cout << "N - New account" << endl;
    log << "N - New account" << endl;
    cout << "B - Balance" << endl;
    log << "B - Balance" << endl;
    cout << "I - Account Info" << endl;
    log << "I - Account Info" << endl;
    cout << "C - Close Account" << endl;
    log << "C - Close Account" << endl;
    cout << "Q - Quit" << endl;
    log << "Q - Quit" << endl;
    cout << "Please make your selection: " << endl;
    log << "Please make your  selection: " << endl;
}

任何形式的帮助将不胜感激!

2 个答案:

答案 0 :(得分:0)

我在Windows上也遇到过这个问题,这对我有帮助。在执行这些命令之前,请确保您的系统环境变量具有 C:\ Python34 \ C:\ Python34 \ Scripts \ 。我的Python版本也是2.7.12,我使用的是Windows 8

首先安装virtualenv(如果已经安装了virtualenv,则跳过)

python -m pip install virtualenv

然后转到要创建虚拟环境的目录并点击

virtualenv venv

激活虚拟环境

venv\Scripts\activate.bat

安装Django

pip install django

这应该在您的虚拟环境中安装django。现在开始一个django项目,正常的 django-admin.py startproject 对我来说不起作用。这对我有用:

python C:\<PATH-TO-VENV-FOLDER>\Scripts\django-admin.py startproject myproject

希望这会有所帮助:)

答案 1 :(得分:0)

  1. 首先检查python是否运行.. python
  2. 然后安装虚拟环境.. python3 -m venv yourEnv_name
  3. 现在安装django .. pip install django