Having trouble adding a library to my script (resolved)

Hello
I am not sure what’s the problem exactly since I remember distinctively being able to add a library to my script, but I can’t anymore,

I was trying to use the request(s) library, which seems to be, an internal library if I am not wrong? See:
image

I tried to make this little script work:

# Serializing a GET Request with .json()
import requests
resp = requests.get('https://reqres.in/api/users')
resp_dict = resp.json()

print(type(resp_dict))

# Returns: <class 'dict'>

(Described here: response.json() - Working with JSON in Python requests • datagy)

Except i get an error for this very first import:

import requests

__

If I remember correctly I had in the past successfully installed a new library using pip, by moving to the pip directory, here:

Python37\Python37\Scripts

I remember I had to use this because this is a “LOCAL” version of capella, I don’t want to mix my “pip install” with other variable environement for other version of python ( How to Set Environment Variables in Windows 10 (alphr.com))

I think I had to do it every time and it was not saved? Anyway I had stoped my experiments that time and moved to other tasks.


Except today, I can’t even install a new library, in fact “PIP” itself does not work, here is an interesting message error that the CMD window displays:

Interesting right? (this is not the latest version of P4C by the way),
CHECK the name “YVANLUSSAUD” inside the ERROR MESSAGE. :astonished:


What worked for me in the past was calling a library like this:
image

So I went ahead and tried the same method with “Requests”,

from requests import *

Result:

ModuleNotFoundError: No module named 'requests'

I did not get that error for “tkinter” or “copy”…

What could be wrong?
Thanks

Just remembered there was a page documentation explaining how to install new python packages: python4capella/InstallNewPythonPackage.textile at master · labs4capella/python4capella · GitHub

I tried to update pip first HOWEVER it did not work, check this:

What’s up with this?
Of course I still can’t install “requests”

I tried updating pip after unpacking Python37.zip in an other folder and it worked. Since you have more than one installation of Python on your machine, you might want to make sure you are using the local one and not the one that might be on your PATH:

.\python.exe -m pip install --upgrade pip

And yes there are some path references to my system even if this version of Python is marked as portable. Not sure why…

EDIT: I also installed the requests module:

Scripts\pip install requests
1 Like

Yes Yvan, that’s what I tried to do actually (going to my python installation),
I have the same problem.
I tried to add a “.\” just in case, i still have the same problem:

Trying googling a bit, found these, not sure if it has any link, does not seem to.
4 Ways to fix SSL: CERTIFICATE_VERIFY_FAILED in Python - howtouselinux

I tried to move my python37 to Desktop, where I have arguably more “rights” as a user (I am not admin by the way) and Still got that authentification fail.

I guess I should try on a more open network/computer.
If you have any computer with “limited rights”, you could try on it and see if you encounter the same problem? If you have any other leads I am all ears, thanks.

After further invertigation, it might be related to the firewall indeed (which I cannot control),
python - ‘SSLError’ installing with pip - Stack Overflow

Someone said something interesting:

I found by trial and error that 20.2.4 was the highest version that works for me with python 3.7.9

I am using (21.2.4), is that okay?

This is a bit infortunate.

Edit: QUESTION:
“pip” HAS TO/ Must be upgraded to be able to install libraries, is that correct?

I think it is mandatory yes, it’s probably related to the hard coded pathes you noticed earlier. Maybe you can try to install a given version of pip:

.\python.exe -m pip install pip==21.2.4

But Python will warn you if you don’t use the last version of pip to install package. I don’t know what might go wrong if you use an outdted version of pip to install a package.

I am already using (20.2.4), don’t know where it came from,

On that other thread someone said a version that worked for him (20…), maybe i should DOWNGRADE?

I tried to ge the latest instead:

.\python.exe -m pip install pip==22.3

Same warnings (orange ones on image from last posts) + a different error:

ERROR: Could not find a version that satisfies the requirement pip==22.3.0 (from versions: none)
ERROR: No matching distribution found for pip==22.3.0

Also tried:

.\python.exe -m pip install pip==22.3.0

(edit: also tried .\python.exe -m pip install pip=="22.3" with " " )
It seems I am not even getting the name of packaging right, so impossible to test if a downgraded version of pip could do the job? What would be lowest correct version?



Would not be there a method to upgrade it locally (using a package containing the new “pip” you want to install)?
(Same as installing directly from packages.zip files, something similar to using an “update site” directory to install an addon on Capella)

Tried also:

python -m pip install --user --upgrade library==20.2.4

(I am thinking an older version could also work), result:

ERROR: Could not find a version that satisfies the requirement library==20.2.4 (from versions: none)
ERROR: No matching distribution found for library==20.2.4

(same as for “21.2.4”)


I will probably not be the ONLY person who will be using Capella in a protected Network (restricted FireWall),
many people might encounter the same problem ( needing to upgrade pip and not being able to).


I would like to clarify something. You know when i install Capella addons, I do never use URLS, because it will never work, however using update sites directories or just drag and droping the addons will allow my capella to use new addons.


Now, I was wondering if it was possible to obtain a version of Python4Capella, where I would not need to upgrade “pip”? Or similar solution.
Thanks

You can try the following with a computer connected to the Internet and then transferring the download folder to the computer not connected to the Internet:

That’s a nice link, I will save it for future use, when needed.
I was aware of the method of installing a package after downloading the package directly, you or your colleagues has explained it on this page:

The problem here is “pip” → I cannot use it.
If you don’t upgrade it, it would not get rid of this error message:

Fatal error in launcher: Unable to create process using '"c:\users\ylussaud\downloads\python37\python.exe" 

A solution would be obtaining the “package of pip”, but again using that package would need… “pip” itself.

Btw, I have internet but its “limited”, I can download the packages, but cannot upgrade pip somehow → therefore cannot use “pip” at all. It seems.

Edit: Found a solution: you must use attribute --trusted-host !

1 Like