Learn Python the Hard Way Exercise 46: Installing

2019-05-11 13:51发布

I am learning Python using Zed Shaw's "Learn Python the Hard Way" on Windows using PowerShell. I am in Exercise 46 where you set up a skelton project. I downloaded pip, distribute, nose, and virtualenv and I installed them by typing:

python <filename>.py install

However, probably because they were not installed where they were supposed to, when I try

nosetests

I get errors saying "The term 'nosetests' is not recognized as the name of a cmdelt, function, script file, or operable program. Check the spelling of the mae, or if a path was included, verify that the path is correct and try again.... CommandNotFoundException".

I have been going through the exercises fine, so I thought that the path was correct but do you have to change it now? Right now, I have the packages under the directory where I have my skelton (..project/skelton). I am sorry for a real-beginner question but if anybody could help me with this, I highly appreciate it!!

3条回答
Lonely孤独者°
2楼-- · 2019-05-11 13:59

I had the same error but the answer was in the book. Type this into powershell, hope it works for you too.

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")
查看更多
混吃等死
3楼-- · 2019-05-11 14:11

Maybe this is late for your question, but this may help others that will experience the same issue that we've experienced. I've got mine working doing the ff. steps:

(Assuming that you've downloaded all packages as discussed in the book):

  1. pip from https://bootstrap.pypa.io/get-pip.py (save that as python file)
  2. distribute from http://pypi.python.org/pypi/distribute
  3. nose from http://pypi.python.org/pypi/nose/
  4. virtualenv from http://pypi.python.org/pypi/virtualenv

Follow this to install all:

  • Run Windows Powershell as Administrator
  • cd C:\Path_Where_You_Downloaded_get-pip.py
  • Install pip by using the command 'python get-pip.py'
  • Run Command Prompt as Administrator
  • cd to location of Python27 scripts (in my case C:\Python27\Scripts)
  • Try to update pip using the command 'pip install --upgrade pip'
  • Install Nose by using this command 'pip install C:\Path_Where_You_downloaded_nose'
  • Install distribute using command 'pip install distribute'

Hope this helps!

查看更多
淡お忘
4楼-- · 2019-05-11 14:19

Try this:

// make sure you have pip and virtualenv installed
cd project
// create a virtual environment
virtualenv venv --distribute
// activate the virtual environment 
// I'm not 100% sure, but I think this is correct way on windows
venv\Scripts\activate.bat
// install nose
pip install nose

You should now be able to run nosetests as long as your virtualenv is activated.

查看更多
登录 后发表回答