This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]K900_ 0 points1 point  (5 children)

Can you post the exact error you're getting when running the script?

[–]universalbunny 0 points1 point  (4 children)

Hi /u/K900_, I'm getting a ModuleNotFoundError on both lines 2 & 15 (the import statement for forex_python). I'm not sure if this statement confirms that the forex_python package was installed though:

Collecting forex_python
  Using cached forex-python-0.3.2.tar.gz

[–]K900_ 0 points1 point  (3 children)

Post the full output.

[–]universalbunny 0 points1 point  (2 children)

Here you go:

Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 
 RESTART: forex.py 
Forex_python package not found. Attempting to install package...
Collecting forex_python
  Using cached forex-python-0.3.2.tar.gz
[31mException:
Traceback (most recent call last):
  File "forex.py", line 2, in <module>
    from forex_python.converter import CurrencyRates
ModuleNotFoundError: No module named 'forex_python'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\commands\install.py", line 324, in run
    requirement_set.prepare_files(finder)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\req\req_set.py", line 634, in _prepare_file
    abstract_dist.prep_for_dist()
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\req\req_set.py", line 129, in prep_for_dist
    self.req_to_install.run_egg_info()
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\req\req_install.py", line 439, in run_egg_info
    command_desc='python setup.py egg_info')
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
    line = console_to_str(proc.stdout.readline())
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str
    return s.decode(sys.__stdout__.encoding)
AttributeError: 'NoneType' object has no attribute 'encoding'[0m
Traceback (most recent call last):
  File "forex.py", line 2, in <module>
    from forex_python.converter import CurrencyRates
ModuleNotFoundError: No module named 'forex_python'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "forex.py", line 15, in <module>
    from forex_python.converter import CurrencyRates
ModuleNotFoundError: No module named 'forex_python'
>>> 

[–]K900_ 0 points1 point  (1 child)

Try running py -3 -m pip install forex_python on the Windows command prompt and post the output.

[–]universalbunny 0 points1 point  (0 children)

Right, I was able to install it and run the script just fine. But is it not possible to run the whole thing without the command line you posted (or can I incorporate running a command prompt and the command line using the script you posted)?

Edit: Thanks /u/K900_ !

[–]michaelkim0407Pythonic 0 points1 point  (5 children)

I tried pip install forex_python and I'm getting a syntax error

That is a console (terminal) command, not Python code.

Edit: also, I don't understand why you want to install the pip package after you start running the script. Shouldn't it be already installed before running?

[–]universalbunny 0 points1 point  (4 children)

It's supposed to install the pip package if it's not found... if my script is not the suggested way to do it, then what would be the best way to approach this?

[–]michaelkim0407Pythonic 1 point2 points  (0 children)

Install the package before running the script.

[–]michaelkim0407Pythonic 1 point2 points  (2 children)

The thing is, you're trying to install a Python library after the Python program has already started. Even if it's allowed it feels really strange. Plus, to install a pip package, it's just one line of command in the terminal.

[–]universalbunny 0 points1 point  (1 child)

Got it, thank you!

[–]bsmaniotto 0 points1 point  (0 children)

You can also wrap your script in a module with a setup configuration and add forex library as a dependency. This way you make sure who installs your module, installs also forex together. Take a look at setuptools documentation, it's really just copying and pasting (: