[Tutor] [newbie] import error after restart (virtualenv)

David ldl08 at gmx.net
Sat Sep 19 18:21:42 CEST 2015


Hello Peter,

this was indeed the problem -- I didn't go through manage.py! Weird I
didn't have that on the radar anymore.

Putting lists/ onto the Python path did not solve the problem.

Thanks for your help!

David



On 19/09/15 16:07, Peter Otten wrote:
> David wrote:
> 
>> Dear Tutors,
>>
>> I am reading through Harry Percival's "Test-Driven Development with
>> Python".
>>
>> As I finished chapter 3 yesterday, I was fully on track, perfectly
>> aligned with the book.
>>
>> Today I restarted my computer, activated the virtualenv in question --
>> and get an error message that was not there beforehand:
>>
>>
> (Percival_TDD)david at lubuntu:~/PycharmProjects/Percival_TDD/superlists/lists$
>> python tests.py
>> Traceback (most recent call last):
>>   File "tests.py", line 5, in <module>
>>     from lists.views import home_page
>> ImportError: No module named 'lists'
>>
>>
>> I neither understand why he doesn't find 'lists' anymore nor do I know
>> how to solve the problem. Nothing seems to have changed in the meantime...
>>
>> Can you please guide me towards a solution?
>>
>> Thank you!
>>
>> David
>>
>>
>>
>> The project structure looks as follows:
>>
>> (Percival_TDD)david at lubuntu:~/PycharmProjects/Percival_TDD/superlists$
>> tree .
>> ├── db.sqlite3
>> ├── functional_tests.py
>> ├── lists
>> │   ├── admin.py
>> │   ├── __init__.py
>> │   ├── migrations
>> │   │   └── __init__.py
>> │   ├── models.py
>> │   ├── tests.py
>> │   └── views.py
>> ├── manage.py
>> └── superlists
>>     ├── __init__.py
>>     ├── __pycache__
>>     │   ├── __init__.cpython-34.pyc
>>     │   ├── settings.cpython-34.pyc
>>     │   ├── urls.cpython-34.pyc
>>     │   └── wsgi.cpython-34.pyc
>>     ├── settings.py
>>     ├── urls.py
>>     └── wsgi.py
> 
> Given this layout you have to ensure that the parent folder of lists is in 
> sys.path. This can be achieved by setting the PYTHONPATH variable for just 
> this invocation
> 
> $ PYTHONPATH=.. python tests.py
> 
> or in a more permanent way and preferably with absolute paths.
> 
> However, are you sure you ran tests.py explicitly? I've only had a cursory 
> look at django and no project handy to check, but if I remember correctly
> 
> $ ./manage.py test
> 
> should take care of the details.
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> 



More information about the Tutor mailing list