Learn Python the Hard Way Exercise 46: Installing Python packages (pip, nose etc.) on Windows

纵然是瞬间 提交于 2019-12-07 16:07:06

问题


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!!


回答1:


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")



回答2:


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.




回答3:


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!



来源:https://stackoverflow.com/questions/11511809/learn-python-the-hard-way-exercise-46-installing-python-packages-pip-nose-etc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!