Jump to content
JohnLM

How do I "Import" Libraries using Python4Delphi?

Recommended Posts

Specs: Delphi XE7, VCL, Win7 64Bit - current version of Python v2.7.9rc1 as of today 2/1/2025 Friday -- edit: will update it to latest for win7, to v3.8.10

 

As part of my learning of Python and using Python4Delphi as the learning real-time GUI tool, I came across a youtube tutorial video where the person was calling the following Import libraries: 

import pandas as pd
import matplotlib.pyplot as plt
import networkx as nx

In other learning python projects I have imported some libraries successfully.   The ones above are not avail on my laptop.  So I am guessing that I have to download them. 

 

1. Where can I download them from?

2. and where (hdd folder) do I download them to on my laptop?

 

Please note: that I am not using any official Python IDE GUI app.  I am using Python4Delphi and building a small IDE for it and am using that as the IDE GUI app to run python code and/or test and run python lessons with. 

 

Edited by JohnLM
added my system/work specs

Share this post


Link to post

pip is not on my machine.  I searched around for it.  Also, after some time searching some more, I found out how to tell which version of Python I have installed, which is currently at version 2.7.9rc1 and I must have installed it back in 2014 since the date of the folder "Python27" shows that year it was created.   To the best of my memory, I got interested in it when I heard about and watched a youtube video on Python4Delphi by Jim Mckeeth and I must have installed to try it out back then and then forgot about it until around now.  But the version I have seems to work fine, and I've tried many lessons successfully. Just basic stuff.  But now I want to get into it more deeper. 

 

Oh, and I searched around for "pandas" or a folder at least, and I did not find any.  It looks like I have a bit of research to do. 
 

Edited by JohnLM
typos

Share this post


Link to post

Thanks.  Okay, I found the last version of Python being made for Windows 7 is v3.8.10 - After that version, only Windows 10 and onward - 😞

 

link --> https://www.python.org/downloads/release/python-3810/

download link 64b --> https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64.exe

download link 32b --> https://www.python.org/ftp/python/3.8.10/python-3.8.10.exe 

Share this post


Link to post

Apparently, I did have v3.8.10 installed, but the installation must have missed some things I did not tick at the time of initial installation.

 

I proceeded to uninstall it and reinstall it and making sure I tic the part about adding it the search path. 

 

Afterwards, the installation went successfully and I type in PIP and the process worked.   

 

Below is a run-through of the process for the command line: PIP install pandas

 

C:\Users\dell>pip install pandas
Collecting pandas
  Downloading pandas-2.0.3-cp38-cp38-win_amd64.whl (10.8 MB)
     |████████████████████████████████| 10.8 MB 1.3 MB/s
Collecting python-dateutil>=2.8.2
  Downloading python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)
     |████████████████████████████████| 229 kB 1.7 MB/s
Collecting numpy>=1.20.3
  Downloading numpy-1.24.4-cp38-cp38-win_amd64.whl (14.9 MB)
     |████████████████████████████████| 14.9 MB 1.6 MB/s
Collecting pytz>=2020.1
  Downloading pytz-2025.1-py2.py3-none-any.whl (507 kB)
     |████████████████████████████████| 507 kB 1.3 MB/s
Collecting tzdata>=2022.1
  Downloading tzdata-2025.1-py2.py3-none-any.whl (346 kB)
     |████████████████████████████████| 346 kB 1.3 MB/s
Collecting six>=1.5
  Downloading six-1.17.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six, tzdata, pytz, python-dateutil, numpy, pandas

Successfully installed numpy-1.24.4 pandas-2.0.3 python-dateutil-2.9.0.post0 pyt
z-2025.1 six-1.17.0 tzdata-2025.1
WARNING: You are using pip version 21.1.1; however, version 25.0 is available.
You should consider upgrading via the 'c:\users\dell\appdata\local\programs\pyth
on\python38\python.exe -m pip install --upgrade pip' command.

C:\Users\dell>

I am not sure that it installed in the correct place.  I mean, I did not give it a folder/path name.  I just opened a comand line prompt via CMD and the default folder showed, thus, c:\users\dell

 

I am not a Python guru.  Can anybody confirm that I performed this operation correctly?  

 

Edited by JohnLM
typos

Share this post


Link to post

Update on this endeavor. . . 

 

I believe I have properly installed all the necessary libraries as mentioned in my first post.   However, I seem to be having trouble with Python4Delphi issuing the following error due to some issue with this library in this line: "import matplotlib.pyplot as plt" 

 

AttributeError: partially initialized module 'numpy' has no attribute

'__version__' (most likely due to a circular import)

 

and the full errors as reported by Python4Delphi: 

 

python script: 

import matplotlib.pyplot as plt
import numpy as np


Python run output results: 

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\dell\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\__init__.py", line 255, in <module>
    _check_versions()
  File "C:\Users\dell\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\__init__.py", line 250, in _check_versions
    if parse_version(module.__version__) < parse_version(minver):
AttributeError: partially initialized module 'numpy' has no attribute '__version__' (most likely due to a circular import)

I am trying to learn how to produce charts and graphs, like you can do in Excel.  I have tried several different lessons that use import libraries and so far, the only library giving me trouble is "matplotlib.pyplot". 

 

I am failing miserably in this Python4Delphi endeavor!!  Does anyone here know how I can resolve this?


 

Edited by JohnLM
typo

Share this post


Link to post

Looks like an installation problem.

Solving the AttributeError: Module 'numpy' has no attribute '__version__' | Saturn Cloud Blog

 

I would start afresh:

  • Uninstall existing python
  • Grab the most recent python from www.python.org
  • Use pip to install any modules you need

Then test

  • Open the python CLI
  • >>> import numpy
  • etc.

And finally find a good python tutorial to get started, using of course PyScripter.:classic_biggrin:

 

Edited by pyscripter

Share this post


Link to post

update on this issue. . . not resolved. 

 

This issue must be related to the older version (3.8.10) and Windows 7, not to mention the different updates made to the packages over time. 

 

I went to the website you linked to and have been going through the steps, (plus doing other research of my own).  And I have not been able to get these steps working. 

 

For example: 

 

1. python -m venv c:\myenv  # i decided to make it easier to navigate to, so I made the folder at the c:\ root instead. 
2. Then, activate the virtual environment:
2b. source myenv/bin/activate <-- does not work 

 

There is no program called source.  But, after a while I came to realize that maybe they are saying to CD over into the folder? ..in order to use PIP and Python.exe 

 

Anyway. That folder does not exist in step 2b.  It is called myenv/scripts/ and all the .exe files are in there. 

 

I will come back to this an try to figure out how to redirect the PATH to the myenv folder so I can run test via my app.  Or else I will have to figure a way to rename the folders temporarely.  I got the folder renamer working.  I Just have to do some additional hacks to get it to "swap" back and forth once I figure out the issue with the numpy part.  So, if I want my ide 4 python to work with the myenv/script folder, I will have to swap the original Python folder and myenv/script folder. 

 

This is the method that I started working first instead of figuring out how to change the env PATH string. I don't know. I'm not knowledge in Python and all its trouble-shooting, so I am hacking. okay. am late for work. will give an update later. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×