Lara
Lara

Reputation: 2236

Run external file via command line importing Django apps

Simple question as that, but I can't find the answer.

I have a python script located into one of my Django apps - in my django Project.

I'm using PyCharm IDE and local development works fine, I run scripts using CTRL + ALT + R, as below:

from location.crawlers.crawler_cities import *

The problem is, when I have to do it in my Live Server, I have no clue how to import it, I'm doing this:

  1. Activate virtualenv
  2. Go to project folder
  3. Run python (Here I think is the problem is running the python outside my virtualenv not the python installed in my virtualenv itself)
  4. from location.crawlers.crawler_cities import *

I then, finally I get this error

ImportError: No module named location.crawlers.crawler_cities

Any ideas how can I run this in Live Server?

Upvotes: 0

Views: 189

Answers (1)

Zartch
Zartch

Reputation: 1025

Try to append the route of your django project to your PYTHONPATH, before you call the import.

import sys
sys.path.insert(0, '/path/to/project')

Upvotes: 1

Related Questions