0

I am learning Python specifically for data science and have little programming language although I'm a bit more familiar with R.

I installed some modules e.g. pandas and matplotlib, using the code:

python -m pip install [name_of_package]

which appear to be successfully installed, however, the console cannot find the packages when I type: import pandas

What I discovered was that the packages and Python have different paths. For Python, the path is:

C:\Users\stone\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.9

For the packages, the path is:

c:\users\stone\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages

I believe the different paths are responsible for Python not finding the packages.

My question, therefore, is how can I point pip to install in the Python path? In other words for the import to be successful.

This entry seems to be similar to my question but the answers are confusing and may have been become out of date. If answering, please be explicit with the code. I'm very new to this.

Note: I really don't want to install it in a virtual environment because it is needed presently.

Thank you in advance.

Amaks
  • 95
  • 2
  • 6
  • How did you install python? The second path almost looks like a virtual environment for python which is a standard practice for python but the path is a little weird. – TeddyBearSuicide Jun 05 '21 at 01:51
  • @Mythalorian I installed the python exe form https://www.python.org/downloads/ and thereafter ran the download to install it. I don't mind uninstalling and reinstalling the modules provided I could get it to the same folder as python. Do you know how to do that? Also, did I install the modules in a virtual environment when I didn't mean to? That tells you everything about my expertise. – Amaks Jun 05 '21 at 07:39

2 Answers2

2

Python is probably not finding your pandas library, because it's installed in a folder where python is not looking into by default.

When you type "import pandas" python is going to look for a package named pandas within a list of folders set by default.

To solve your issue you can move/reinstall pandas into a folder which python searches through by default or you can add another folder to search through.

Here's a way to do it with python adding directory to sys.path /PYTHONPATH

user14518362
  • 320
  • 4
  • 11
  • 1
    Thanks for answering but I didn't try this suggestion although it may have worked. I uninstalled all python programme and reinstalled but making sure that the adjust the system PATH environment variable was selected. – Amaks Jun 05 '21 at 09:26
0

I am the original poser of the question and found a simple solution that worked for me based on the recommendation of python.org.

  1. First, I uninstalled all python programme from my system
  2. During the reinstall, I checked the box to allow adjust the system PATH environment variable
  3. After installing, I used the `python -m pip install [name_of_package] to install the pandas packages.

These solved the problem and I am now able to import packages without an error message.

The current path to packages is now:

c:\users\stone\appdata\roaming\python\python39\site-packages
Amaks
  • 95
  • 2
  • 6