-1

I already have pip installed but I tried this code to install pandas in my Python27/Lib:

import os
os.system('pip install pandas')

and the tried samples here in : Installing python module within code

and also tried the setup.py here in :https://github.com/pandas-dev/pandas

but this doesn't download pandas and numpy in my Python27/Lib any answers?

UPDATE:

I tried this: and currently installed pandas in my Python

try: import pandas
except ImportError:
    from pip._internal import main as pip
    pip(['install', '--user', 'pandas'])
    import pandas

but I have this error:

[33mYou are using pip version 18.0, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.[0m

Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\OJT\scanner\install.py", line 5, in <module>
    import pandas
ImportError: No module named pandas

Is there a way to install the updated version of pip?

  • This question was previously discussed, already: https://stackoverflow.com/questions/12332975/installing-python-module-within-code – akhavro Oct 09 '18 at 08:11
  • I already tried that link, can't you see my question? –  Oct 09 '18 at 08:17
  • "Is there a way to install the updated version of pip?" - The answer is there already: `pip install --upgrade pip` – normanius Oct 09 '18 at 08:39
  • Does it work to install pandas via the command line? Hint: Check the paths of your python session, for example with `import site; site.getsitepackages()` and compare with `python -m site`. Also, make pip print extra debug information with some verbose flag. – normanius Oct 09 '18 at 08:47

1 Answers1

0

You can look at the subprocess module in the standard library:

from subprocess import call
call(["pip", "install", "pandas"])
Maksym Rudenko
  • 561
  • 3
  • 16
  • WindowsError: [Error 2] The system cannot find the file specified –  Oct 09 '18 at 08:16
  • I can't test it, I don't have Windows, but do you have pip installed? [instruction](https://stackoverflow.com/questions/4750806/how-do-i-install-pip-on-windows) – Maksym Rudenko Oct 09 '18 at 08:29