analitics

Pages

Tuesday, January 24, 2023

Python 3.8.10 : My colab tutorials - part 029.

Colab from google is a great tool when you want to write equations. I show a simple example with LaTeX formula with this colab notebook named catafest_034.

Python : Fix DLL load failed while importing ...

This error DLL load failed while importing ... can have many causes like conflicts with the already installed packages, and also it can break your current environment.
>>> import PyQt6
>>> from PyQt6.QtCore import QUrl
Traceback (most recent call last):
  ...
ImportError: DLL load failed while importing QtCore: The specified module could not be found.
You can see I used to reinstall the PyQt6 python package with this argument --ignore-installed:
pip3 install PyQt6 --user --ignore-installed
Collecting PyQt6
  ...
Installing collected packages: PyQt6-Qt6, PyQt6-sip, PyQt6
  WARNING: The scripts pylupdate6.exe and pyuic6.exe are installed in
  ...
  which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed PyQt6-6.4.0 PyQt6-Qt6-6.4.2 PyQt6-sip-13.4.0
The --ignore-installed option for the pip package manager was first introduced in version 6.0, which was released in April 2014.
The old install give me this error and when I try to use I got this:
>>> from PyQt6 import *
>>> dir(PyQt6)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
Now after I reinstall with this option the result is good:
>>> import PyQt6
>>> from PyQt6 import QtCore
>>> dir(PyQt6)
['QtCore', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'sip']
>>> from PyQt6.QtCore import QUrl

Python 3.11.0 : The openai python package - part 001.

The OpenAI Python library provides convenient access to the OpenAI API from applications written in the Python language. It includes a pre-defined set of classes for API resources that initialize themselves dynamically from API responses which makes it compatible with a wide range of versions of the OpenAI API.
You can see more about this on the GitHub project.
in order to use this package you need to have a A.P.I. key for OpenAI beta features from this website.
Create a key and copy into file or clipboard beacuse this cannot be accesed after you created.
Use the pip tool to install the openai package:
pip3 install openai --user
I tested with a default example and a simple question: What is the python programmin language?
import os
import openai


openai.api_key = "your_API_OpenAI_key"

response = openai.Completion.create(
    model="text-davinci-003",
    prompt="What is the python programmin language?",
    temperature=0.7,
    max_tokens=100,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0
)

print(response)
I run this python script code and the result is this:
python openai001.py
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "logprobs": null,
      "text": "\n\nPython is a high-level, interpreted, general-purpose programming language. 
      It was created by Guido van Rossum and first released in 1991. Python has a wide variety of 
      uses and is a popular language for data science, web development, automation, and artificial 
      intelligence. It is also a popular language for scripting and general-purpose programming."
    }
  ],
  "created": 1674588982,
  "id": "cmpl-6cJNeACMtayBlExV1GJpilde0KcBN",
  "model": "text-davinci-003",
  "object": "text_completion",
  "usage": {
    "completion_tokens": 71,
    "prompt_tokens": 8,
    "total_tokens": 79
  }
}