1

I am trying to run a py.test script. When the script try to import py, I get a "No module named py"

I have py.test and python successfully installed.

My error message:

$ python >>> import py Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named py 

The sqript I am trying to run, are named run_tests.py, and are made by my University. It runs for all other people. It starts like this:

# This script can be used to automatically check the assignments of students import py import os import sys import argparse verbose = True # List of assignment names and achie..... 

My py.test version: 2.7.2, python version: 2.7.9, runing OSX

3
  • 1
    There is no module named py. Do you mean that you wrote a script and saved it as py.test? Why would you do that and why would you expect Python to look for a file named py.test when you write import py? Commented Sep 21, 2015 at 12:58
  • @JohnColeman: there is library named py: pypi.python.org/pypi/py/1.4.30 Commented Sep 21, 2015 at 13:05
  • @TommasoDiBucchianico good to know -- I should have said that there is no standard module which is part of the default Python install. Commented Sep 21, 2015 at 13:15

2 Answers 2

3

Install the py library on your system:

pip install py 
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, just did this, still have the same problem. $ pip install py Requirement already satisfied (use --upgrade to upgrade): py in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages Cleaning up... $ python >>> import py Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named py
Are you sure, you are using python 2.7? What does python --version say? anyway try also pip install py --upgrade
$ python --version say Python 2.7.9, pip install py --upgrade did not help. Still get the same message
0

I did figure it out myself.

I had an alias in my bash profile:

alias python="python2.7" 

That messed up. I removed it and everything works. facepalm

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.