WebFaction
Community site: login faq

I have installed a Python module to python 2.7 on my space. I can import the module if I start python with python2.7 on the shell then do import modulename. But I can't import the module if I am running an actual python file as a script. I tried #!/usr/local/bin/python2.7 as the first line but it's still not working. So, how do I run a python script as a certain version of python so I can use a module I imported for that version?

asked 07 Mar '13, 12:12

guss
113
accept rate: 0%


When you are running the script you can specify the python version number by appending the python command with the version. For example:

python2.7 /path/to/script

From cron you need to use the full path to the executable:

/usr/local/bin/python2.7 /path/to/script
permanent link

answered 07 Mar '13, 12:34

timg ♦♦
1.3k4
accept rate: 30%

I should have specified — I mean when running from the browser. For example if someone navigates to example.com/blah.py it should use python2.7.

(07 Mar '13, 12:53) guss

Using the shebang #!/usr/local/bin/python2.7 should set to python2.7. You can also try #! /usr/bin/env python2.7. If neither work, Please open a ticket at our support site, and we'll help you find a solution.

(07 Mar '13, 13:12) timg ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×337
×21
×15

question asked: 07 Mar '13, 12:12

question was seen: 4,281 times

last updated: 07 Mar '13, 13:12

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM