1

So I've written a desktop application on Python. It works fine when I run it by manually clicking 'Run main' through the IDE but when I do: python main.py the terminal does find the program but doesn't recognize the libaries.

I've tried installing the libaries/modules a couple of times on the terminal and it says i've installed them but i guess not. These are the libaries/modules that refuses to work.

from iconsdk.icon_service import IconService
from iconsdk.providers.http_provider import HTTPProvider

The output on the console (when I run 'python main.py') is this:

Traceback (most recent call last): File "main.py", line 1, in import gui File "/Users/adam/PycharmProjects/igotmemed/gui.py", line 9, in import blockgen File "/Users/adam/PycharmProjects/igotmemed/blockgen.py", line 2, in from iconsdk.providers.http_provider import HTTPProvider File "/Users/adam/miniconda3/lib/python3.7/site-packages/iconsdk/providers/http_provider.py", line 17, in import requests File "/Users/adam/miniconda3/lib/python3.7/site-packages/requests/init.py", line 43, in import urllib3 File "/Users/adam/miniconda3/lib/python3.7/site-packages/urllib3/init.py", line 8, in from .connectionpool import ( File "/Users/adam/miniconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 26, in from .packages.ssl_match_hostname import CertificateError ImportError: cannot import name 'CertificateError' from 'urllib3.packages.ssl_match_hostname' (unknown location)

Something significant to note is 'CertificateError'.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • I guess one thing I am looking for is what happens in the background when I run a file on Pycharm. Because it's clearly different to running it via the terminal. – Charles Jonasson Jan 28 '19 at 11:14
  • when you run your program from pycharm. it includes all the required files needed to run your program on the other hand running it on the terminal would require including all the required files manually hence causing nasty errors. :) That is why you call it an IDE. because it does most of the work on its own. – Ahtisham Jan 28 '19 at 11:38
  • So what do I have to do now? I am not able to create an exe file from Pycharm with these scary errors :( – Charles Jonasson Jan 28 '19 at 11:48
  • pycharm projects run within a virtual environment (which is the correct way to run any python project). so [learn about python virtual environments](https://realpython.com/python-virtual-environments-a-primer/) and make sure you activate your virtual environment when in the terminal. – dirkgroten Jan 28 '19 at 12:13

1 Answers1

0

Did you create your project with PyCharm? Because I think it also creates a virtual environment by default. Here is how the new project screen looks like: enter image description here

Checking the location of your virtual env:

In the Settings/Preferences dialog (Ctrl+Alt+S), select Project: | Project Interpreter.

There you should be able to see the location of the project's virtual environment.

Then simply activate that virtual environment from your terminal and run your script.

farkas
  • 307
  • 2
  • 8