Oct-03-2016, 11:43 AM
Hi Everybody
I am trying to learn python and I created my first script with a package that contains an imported module but it does not work!
Both scripts work independently.
I put the package in the site-packages of the virtualenv and no import.
I tried many things but nothing worked and I understood how the import works!
I do not understand why it does not work! Can you help me please ?
Thanks a lot
My OS: Debian 8 KDE
IDE: PyCharm also Vim + terminal
Virtualenv: Python 3.5
My Working directory: PycharmProject
My sys.path with Pycharm:
The main script:
I am trying to learn python and I created my first script with a package that contains an imported module but it does not work!
Both scripts work independently.
I put the package in the site-packages of the virtualenv and no import.
I tried many things but nothing worked and I understood how the import works!
I do not understand why it does not work! Can you help me please ?
Thanks a lot
My OS: Debian 8 KDE
IDE: PyCharm also Vim + terminal
Virtualenv: Python 3.5
My Working directory: PycharmProject
My sys.path with Pycharm:
>>> import sys >>> sys.path ['/home/user/bin/PYTHON/pycharm-community-2016.2.3/helpers/pydev', '/home/user/bin/PYTHON/PycharmProject', '/home/user/bin/PYTHON/pycharm-community-2016.2.3/helpers/pydev', '/home/user/bin/PYTHON/virtualenv/py35/lib/python35.zip', '/home/user/bin/PYTHON/virtualenv/py35/lib/python3.5', '/home/user/bin/PYTHON/virtualenv/py35/lib/python3.5/plat-linux', '/home/user/bin/PYTHON/virtualenv/py35/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5', '/usr/local/lib/python3.5/plat-linux', '/home/user/bin/PYTHON/virtualenv/py35/lib/python3.5/site-packages', '/home/user/bin/PYTHON/PycharmProject'] >>>
~/bin/PYTHON/PycharmProject$ tree ├── courier │ ├── envoi.py │ └── __init__.py └── DiskSpace.pyThe Two littles scripts:
The main script:
#!/usr/local/bin/python3.5 # -*- coding: utf-8 -*- import subprocess #import sys #sys.path.append("/home/user/bin/PYTHON/PycharmProject") #import courier.envoi from courier.envoi import MonCourier class DiskSpace: def espace_disk(self): p = subprocess.Popen("df -h", stdout=subprocess.PIPE, shell=True) (output, err) = p.communicate() tableau = output.split() for index, ligne in enumerate(tableau): if tableau[index].decode('utf8') == "/home": val_index = int(index) val_index_dispo = (val_index - 2) val_giga_dispo = tableau[val_index_dispo].decode('utf8') valeur = int(val_giga_dispo.replace("G", " ")) if valeur <= 5: print("ATTENTION ! ALERTE ! {}G de disponible sur le disk !".format(valeur)) envoi_mon_courier("ALERTE ! {}G de disponible sur le disk !".format(valeur)) else: print("Espace disk disponible est de {}G .".format(valeur)) envoi_mon_courier("Espace disque est de {}G .".format(valeur)) if __name__ == '__main__': disk_server = DiskSpace() disk_server.espace_disk()The module for import:
#!/usr/local/bin/python3.5 # -*- coding: utf-8 -*- import smtplib from smtplib import SMTPException from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText class MonCourier: def envoi_mon_courier(self, msg_info): msg = MIMEMultipart() msg['From'] = '[email protected]' msg['To'] = '[email protected]' msg['Subject'] = 'Espace Disque Server!' message = msg_info msg.attach(MIMEText(message)) try: # Send the message via our own SMTP server. mailserver = smtplib.SMTP('smtp.domain.com', 587) mailserver.ehlo() mailserver.starttls() mailserver.ehlo() mailserver.login('[email protected]', 'admin') mailserver.sendmail('[email protected]', '[email protected]', msg.as_string()) print("Successfully sent email") mailserver.quit() except SMTPException: print("Error: unable to send email") #if __name__ == '__main__': # s = MonCourier() # s.envoi_mon_courier("hello")