0

I'm trying to launch a basic python (loop.pyw file) program via the pythonw.exe program just to see in my task manager if the python script is really executing itself.

Here's the program :

import traceback
import os
try:
    from stem import Signal
except ImportError:
    f1 = open("C:/Users/mtigr/Desktop/Apprentissage-Projets Programmation/Python/ZCHANGEIP/traceback.txt", "a")
    traceback.print_exc(file=f1)
    f1.close()
try:
    from stem.control import Controller
except ImportError:
    f1 = open("C:/Users/mtigr/Desktop/Apprentissage-Projets Programmation/Python/ZCHANGEIP/traceback.txt", "a")
    traceback.print_exc(file=f1)
    f1.close()

try:
    import requests
except ImportError:
    f1 = open("C:/Users/mtigr/Desktop/Apprentissage-Projets Programmation/Python/ZCHANGEIP/traceback.txt", "a")
    traceback.print_exc(file=f1)
    f1.close()
import urllib
try:
    from bs4 import BeautifulSoup
except ImportError:
    f1 = open("C:/Users/mtigr/Desktop/Apprentissage-Projets Programmation/Python/ZCHANGEIP/traceback.txt", "a")
    traceback.print_exc(file=f1)
    f1.close()

import time
import urllib.request as urllib2

while True:
    # Execute program
    print("hi")
    time.sleep(2)

As you can see, I used the traceback tool to print into a file the traceback and here's the result :

Traceback (most recent call last):
  File "C:\Users\mtigr\Desktop\Apprentissage-Projets Programmation\Python\ZCHANGEIP\loop.pyw", line 11, in <module>
    from stem import Signal
ModuleNotFoundError: No module named 'stem'
Traceback (most recent call last):
  File "C:\Users\mtigr\Desktop\Apprentissage-Projets Programmation\Python\ZCHANGEIP\loop.pyw", line 17, in <module>
    from stem.control import Controller
ModuleNotFoundError: No module named 'stem'
Traceback (most recent call last):
  File "C:\Users\mtigr\Desktop\Apprentissage-Projets Programmation\Python\ZCHANGEIP\loop.pyw", line 24, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'
Traceback (most recent call last):
  File "C:\Users\mtigr\Desktop\Apprentissage-Projets Programmation\Python\ZCHANGEIP\loop.pyw", line 31, in <module>
    from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'

The program tells me that the imports are not recognized. I do not understand why because I can execute the program correctly via the command :

python loop.pyw

In a command prompt.

I don't understand what the problem seems to be with the imports. The problem is really with the 3 imports stem, requests and Beautiful soup. I've installed every module correctly and I don't know why it does that, can you help me please? Do I need to specify a folder to pythonw.exe? Can you guide me?

Thank you!

EDIT I finally found the answer. When I installed the modules with pip, it installs them in the Miniconda3 folder (C:\Users\mtigr\Miniconda3\Lib\site-packages). The packages need to also be installed in the Oyhton directory (C:\Users\mtigr\AppData\Local\Programs\Python\Python36-32\Lib\site-packages), because pythonw actually uses this directory and not the Miniconda Directory.

So there is the answer in case someone has the same trouble than me. I discovered the answer by opening the python IDLE and trying to import the different modules and I realised some of them work and others don't so it kinda put me a flea in the ear. Then I checked where the python IDLE was importing those modules from and I discovered it was not the same directory than the one I installed them in.

Anyways have a nice day!

spmegaman
  • 1
  • 2

0 Answers0