• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Resolved python import on Plesk server

DavidMoksha

New Pleskian
I'm writing not as a host, but as a customer of a webhost that uses Plesk Parallels.

I've written a couple simple python scripts to test python on my host, before embarking on a serious project. They are: foo.py and bar.py

If within foo.py I do:
import bar

I get an error in the error.log: ImportError: No module named bar

On my local computer, the import works just fine. People in python forums and IRC similarly advise that this should work just fine.

Why does this not work, and how can I import scripts in the same directory?

One thing I have noticed is that __name__ is not set to '__main__' when going to the url of a python script. Perhaps I am required to use a package? Is there anywhere a guide or tutorial to getting started with these issues programming python for Plesk?

Thanks in advance,
David
 
I have discovered a solution to this problem: the directory where the module resides must be added to the path. On my local machine, the current directory is part of the path; but apparently this is not so on the plesk server I'm using. Here is a code snippet others can use to solve the same problem (update the path to reflect the appropriate directory on your server)

import sys
sys.path.insert(0, '/var/www/vhosts/my.domain/httpdocs/projectdir/')
import bar​

So this works :)
 
Back
Top