FLOSS Project Planets

Test and Code: 192: Learn to code through game development with PursuedPyBear - Piper Thunstrom

Planet Python - Sat, 2022-08-06 19:15

The first game I remember coding, or at least copying from a magazine, was in Basic. It was Lunar Lander.

Learning to code a game is a way that a lot of people get started and excited about programming.

Of course, I don't recommend Basic. Now we've got Python. And one of the game engines available for Python is PursuedPyBear, a project started by Piper Thunstrom.

Piper joins us this episode and we talk about PursuedPyBear, learning to code, and learning CS concepts with game development.

PursuedPyBear, ppb, is a game framework great for learning with, with goals of being fun, education friendly, an example of idiomatic Python, hardware library agnostic, and built on event driven and object oriented concepts.

Special Guest: Piper Thunstrom.

Sponsored By:

Links:

<p>The first game I remember coding, or at least copying from a magazine, was in Basic. It was Lunar Lander. </p> <p>Learning to code a game is a way that a lot of people get started and excited about programming. </p> <p>Of course, I don&#39;t recommend Basic. Now we&#39;ve got Python. And one of the game engines available for Python is PursuedPyBear, a project started by Piper Thunstrom. </p> <p>Piper joins us this episode and we talk about PursuedPyBear, learning to code, and learning CS concepts with game development. </p> <p>PursuedPyBear, ppb, is a game framework great for learning with, with goals of being fun, education friendly, an example of idiomatic Python, hardware library agnostic, and built on event driven and object oriented concepts.</p><p>Special Guest: Piper Thunstrom.</p><p>Sponsored By:</p><ul><li><a href="http://rollbar.com/testandcode" rel="nofollow">Rollbar</a>: <a href="http://rollbar.com/testandcode" rel="nofollow">With Rollbar, developers deploy better software faster.</a></li></ul><p>Links:</p><ul><li><a href="https://ppb.dev/" title="PursuedPyBear | Unbearably Fun Game Development" rel="nofollow">PursuedPyBear | Unbearably Fun Game Development</a></li><li><a href="https://piper.thunstrom.dev/" title="Piper's Blog" rel="nofollow">Piper's Blog</a></li><li><a href="https://www.youtube.com/watch?v=bbKED0o3uVU" title="Making Games With PPB - PyTexas" rel="nofollow">Making Games With PPB - PyTexas</a></li><li><a href="https://pathunstrom.itch.io/shooter-game" title="Shooter Game by Piper Thunstrom" rel="nofollow">Shooter Game by Piper Thunstrom</a></li><li><a href="https://github.com/pathunstrom/shootergame" title="shootergame on GitHub" rel="nofollow">shootergame on GitHub</a></li><li><a href="https://beeware.org/project/projects/tools/briefcase/" title="Briefcase— BeeWare" rel="nofollow">Briefcase— BeeWare</a></li><li><a href="https://github.com/pathunstrom/game-blink" title="game-blink: A tiny emergent behavior toy." rel="nofollow">game-blink: A tiny emergent behavior toy.</a></li><li><a href="https://en.wikipedia.org/wiki/Combat_(Atari_2600)" title="Combat (Atari 2600)" rel="nofollow">Combat (Atari 2600)</a> &mdash; The tank game I didn't remember the name of.</li><li><a href="https://en.wikipedia.org/wiki/Lunar_Lander_(video_game_genre)" title="Lunar Lander" rel="nofollow">Lunar Lander</a></li></ul>
Categories: FLOSS Project Planets

ItsMyCode: ModuleNotFoundError: No module named &#8216;psycopg2&#8217;

Planet Python - Sat, 2022-08-06 15:51

In Python, ModuleNotFoundError: No module named ‘psycopg2’ error occurs if we try to import the ‘psycopg2-binary‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the psycopg2-binary module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘psycopg2’ error.  

What is ModuleNotFoundError: No module named ‘psycopg2’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘psycopg2’ error

  • Trying to use the module- without installing the psycopg2-binary package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the psycopg2-binary module is not installed inside a virtual environment
  • Installing the psycopg2-binary package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(psycopg2-binary)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘psycopg2’?

psycopg2-binary is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

Psycopg is the most popular PostgreSQL database adapter for the Python programming language. Its main features are the complete implementation of the Python DB API 2.0 specification and the thread safety (several threads can share the same connection).

We can fix the error by installing the ‘psycopg2-binary‘ module by running the pip install psycopg2-binary command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: psycopg2-binary.

pip show psycopg2-binary

Output

Name: psycopg2 Version: 2.9.3 Summary: psycopg2 - Python-PostgreSQL Database Adapter Home-page: https://psycopg.org/ Author: Federico Di Gregorio Author-email: fog@initd.org License: LGPL with exceptions Location: c:\personal\ijs\python_samples\venv\lib\site-packages Solution 1 – Installing and using the psycopg2-binary module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the psycopg2-binary module.

# If you are using Python 2 (Windows) pip install psycopg2-binary # if you are using Python 3 (Windows) pip3 install psycopg2-binary # If the pip is not set as environment varibale PATH python -m pip install psycopg2-binary # If you are using Python 2 (Linux) sudo pip install psycopg2-binary # if you are using Python 3 (Linux) sudo pip3 install psycopg2-binary # In case if you have to easy_install sudo easy_install -U psycopg2-binary # On Centos yum install psycopg2-binary # On Ubuntu sudo apt-get install psycopg2-binary # If you are installing it in Anaconda conda install -c conda-forge psycopg2-binary

Once you have installed the psycopg2-binary module, we can now import it inside our code and use it as shown below.

import psycopg2 # Connect to your postgres DB conn = psycopg2.connect("dbname=test user=postgres") # Open a cursor to perform database operations cur = conn.cursor() # Execute a query cur.execute("SELECT * FROM my_data") # Retrieve query results Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

Python Interpreter

Solution 3 – Installing psycopg2-binary inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the psycopg2-binary module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment py -3 -m venv venv # Activate the virtual environment (windows command) venv\Scripts\activate.bat # Activate the virtual environment (windows powershell) venv\Scripts\Activate.ps1 # Activate the virtual environment (Linux) source venv/bin/activate # Install psycopg2-binary inside the virtual environment pip install psycopg2-binary Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as psycopg2.py as it may shadow the original psycopg2-binary module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘psycopg2’ error occurs when we try to import the ‘psycopg2-binary‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the psycopg2-binary module by running the pip install psycopg2-binary command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Categories: FLOSS Project Planets

ItsMyCode: ModuleNotFoundError: No module named &#8216;psutil&#8217;

Planet Python - Sat, 2022-08-06 15:51

In Python, ModuleNotFoundError: No module named ‘psutil’ error occurs if we try to import the ‘psutil‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the psutil module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘psutil’ error.  

What is ModuleNotFoundError: No module named ‘psutil’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘psutil’ error

  • Trying to use the module- without installing the psutil package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the psutil module is not installed inside a virtual environment
  • Installing the psutil package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(psutil)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘psutil’?

psutil is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

psutil (process and system utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python. It is useful mainly for system monitoringprofiling and limiting process resources and management of running processes

We can fix the error by installing the ‘psutil‘ module by running the pip install psutil command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: psutil.

pip show psutil

Output

Name: psutil Version: 5.9.1 Summary: Cross-platform lib for process and system monitoring in Python. Home-page: https://github.com/giampaolo/psutil Author: Giampaolo Rodola Author-email: g.rodola@gmail.com License: BSD Location: c:\personal\ijs\python_samples\venv\lib\site-packages Solution 1 – Installing and using the psutil module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the psutil module.

# If you are using Python 2 (Windows) pip install psutil # if you are using Python 3 (Windows) pip3 install psutil # If the pip is not set as environment varibale PATH python -m pip install psutil # If you are using Python 2 (Linux) sudo pip install psutil # if you are using Python 3 (Linux) sudo pip3 install psutil # In case if you have to easy_install sudo easy_install -U psutil # On Centos yum install psutil # On Ubuntu sudo apt-get install psutil # If you are installing it in Anaconda conda install -c conda-forge psutil

Once you have installed the psutil module, we can now import it inside our code and use it as shown below.

import psutil print(psutil.cpu_times()) print(psutil.virtual_memory())

Output

scputimes(user=679134.796875, system=319145.4375, idle=3937574.28125, interrupt=19485.859375, dpc=23378.8125) svmem(total=16942211072, available=2417156096, percent=85.7, used=14525054976, free=2417156096) Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

Python Interpreter

Solution 3 – Installing psutil inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the psutil module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment py -3 -m venv venv # Activate the virtual environment (windows command) venv\Scripts\activate.bat # Activate the virtual environment (windows powershell) venv\Scripts\Activate.ps1 # Activate the virtual environment (Linux) source venv/bin/activate # Install psutil inside the virtual environment pip install psutil Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as psutil.py as it may shadow the original psutil module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘psutil’ error occurs when we try to import the ‘psutil‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the psutil module by running the pip install psutil command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Categories: FLOSS Project Planets

ItsMyCode: ModuleNotFoundError: No module named &#8216;PyQt5&#8217;

Planet Python - Sat, 2022-08-06 15:51

In Python, ModuleNotFoundError: No module named ‘PyQt5’ error occurs if we try to import the ‘PyQt5‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the PyQt5 module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘PyQt5’ error.  

What is ModuleNotFoundError: No module named ‘PyQt5’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘PyQt5’ error

  • Trying to use the module- without installing the PyQt5 package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the PyQt5 module is not installed inside a virtual environment
  • Installing the PyQt5 package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(PyQt5)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘PyQt5’?

PyQt5 is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

PyQt5 is a comprehensive set of Python bindings for Qt v5. It is implemented as more than 35 extension modules and enables Python to be used as an alternative application development language to C++ on all supported platforms including iOS and Android.

We can fix the error by installing the ‘PyQt5‘ module by running the pip install PyQt5 command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: PyQt5.

pip show PyQt5

Output

Name: PyQt5 Version: 5.15.7 Summary: Python bindings for the Qt cross platform application toolkit Home-page: https://www.riverbankcomputing.com/software/pyqt/ Author: Riverbank Computing Limited Author-email: info@riverbankcomputing.com License: GPL v3 Location: c:\personal\ijs\python_samples\venv\lib\site-packages Requires: PyQt5-Qt5, PyQt5-sip Solution 1 – Installing and using the PyQt5 module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the PyQt5 module.

# If you are using Python 2 (Windows) pip install PyQt5 # if you are using Python 3 (Windows) pip3 install PyQt5 # If the pip is not set as environment varibale PATH python -m pip install PyQt5 # If you are using Python 2 (Linux) sudo pip install PyQt5 # if you are using Python 3 (Linux) sudo pip3 install PyQt5 # In case if you have to easy_install sudo easy_install -U PyQt5 # On Centos yum install PyQt5 # On Ubuntu sudo apt-get install PyQt5 # If you are installing it in Anaconda conda install -c anaconda pyqt

Once you have installed the PyQt5 module, we can now import it inside our code and use it as shown below.

from PyQt5.QtWidgets import * app = QApplication([]) label = QLabel('Hello World!') label.show() app.exec()

Output

ModuleNotFoundError: No module named 'PyQt5' 5 Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

Python Interpreter

Solution 3 – Installing PyQt5 inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the PyQt5 module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment py -3 -m venv venv # Activate the virtual environment (windows command) venv\Scripts\activate.bat # Activate the virtual environment (windows powershell) venv\Scripts\Activate.ps1 # Activate the virtual environment (Linux) source venv/bin/activate # Install PyQt5 inside the virtual environment pip install PyQt5 Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as PyQt5.py as it may shadow the original PyQt5 module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘PyQt5’ error occurs when we try to import the ‘PyQt5‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the PyQt5 module by running the pip install PyQt5 command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Categories: FLOSS Project Planets

ItsMyCode: ModuleNotFoundError: No module named &#8216;pymongo&#8217;

Planet Python - Sat, 2022-08-06 15:51

In Python, ModuleNotFoundError: No module named ‘pymongo’ error occurs if we try to import the ‘pymongo‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the pymongo module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘pymongo’ error.  

What is ModuleNotFoundError: No module named ‘pymongo’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘pymongo’ error

  • Trying to use the module- without installing the pymongo package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the pymongo module is not installed inside a virtual environment
  • Installing the pymongo package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(pymongo)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘pymongo’?

pymongo is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

The PyMongo distribution contains tools for interacting with MongoDB database from Python. The bson package is an implementation of the BSON format for Python. The pymongo package is a native Python driver for MongoDB. The gridfs package is a gridfs implementation on top of pymongo.

We can fix the error by installing the ‘pymongo‘ module by running the pip install pymongo command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: pymongo.

pip show pymongo

Output

Name: pymongo Version: 4.2.0 Summary: Python driver for MongoDB <http://www.mongodb.org> Home-page: http://github.com/mongodb/mongo-python-driver Author: The MongoDB Python Team Author-email: License: Apache License, Version 2.0 Location: c:\personal\ijs\python_samples\venv\lib\site-packages Solution 1 – Installing and using the pymongo module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the pymongo module.

# If you are using Python 2 (Windows) pip install pymongo # if you are using Python 3 (Windows) pip3 install pymongo # If the pip is not set as environment varibale PATH python -m pip install pymongo # If you are using Python 2 (Linux) sudo pip install pymongo # if you are using Python 3 (Linux) sudo pip3 install pymongo # In case if you have to easy_install sudo easy_install -U pymongo # On Centos yum install pymongo # On Ubuntu sudo apt-get install pymongo # If you are installing it in Anaconda conda install -c anaconda pymongo

Once you have installed the pymongo module, we can now import it inside our code and use it as shown below.

import pymongo client = pymongo.MongoClient("localhost", 27017) db = client.test print(db.name)

Output

ItsMyCode Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

Python Interpreter

Solution 3 – Installing pymongo inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the pymongo module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment py -3 -m venv venv # Activate the virtual environment (windows command) venv\Scripts\activate.bat # Activate the virtual environment (windows powershell) venv\Scripts\Activate.ps1 # Activate the virtual environment (Linux) source venv/bin/activate # Install pymongo inside the virtual environment pip install pymongo Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as pymongo.py as it may shadow the original pymongo module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘pymongo’ error occurs when we try to import the ‘pymongo‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the pymongo module by running the pip install pymongo command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Categories: FLOSS Project Planets

ItsMyCode: ModuleNotFoundError: No module named &#8216;pymysql&#8217;

Planet Python - Sat, 2022-08-06 15:51

In Python, ModuleNotFoundError: No module named ‘pymysql’ error occurs if we try to import the ‘PyMySQL‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the PyMySQL module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘pymysql’ error.  

What is ModuleNotFoundError: No module named ‘pymysql’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘pymysql’ error

  • Trying to use the module- without installing the PyMySQL package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the PyMySQL module is not installed inside a virtual environment
  • Installing the PyMySQL package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(PyMySQL)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘pymysql’?

PyMySQL is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

PyMySQL is an interface for connecting to a MySQL database server from Python. It implements the Python Database API v2. 0 and contains a pure-Python MySQL client library. The goal of PyMySQL is to be a drop-in replacement for MySQLdb.

We can fix the error by installing the ‘PyMySQL‘ module by running the pip install PyMySQL command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: PyMySQL.

pip show PyMySQL

Output

Name: PyMySQL Version: 1.0.2 Summary: Pure Python MySQL Driver Home-page: https://github.com/PyMySQL/PyMySQL/ Author: yutaka.matsubara Author-email: yutaka.matsubara@gmail.com License: "MIT" Location: c:\personal\ijs\python_samples\venv\lib\site-packages Solution 1 – Installing and using the PyMySQL module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the PyMySQL module.

# If you are using Python 2 (Windows) pip install PyMySQL # if you are using Python 3 (Windows) pip3 install PyMySQL # If the pip is not set as environment varibale PATH python -m pip install PyMySQL # If you are using Python 2 (Linux) sudo pip install PyMySQL # if you are using Python 3 (Linux) sudo pip3 install PyMySQL # In case if you have to easy_install sudo easy_install -U PyMySQL # On Centos yum install PyMySQL # On Ubuntu sudo apt-get install PyMySQL # If you are installing it in Anaconda conda install -c anaconda pymysql

Once you have installed the PyMySQL module, we can now import it inside our code and use it as shown below.

import pymysql.cursors # Connect to the database connection = pymysql.connect(host='localhost', user='user', password='passwd', database='db', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) with connection: with connection.cursor() as cursor: # Create a new record sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)" cursor.execute(sql, ('webmaster@python.org', 'very-secret')) # connection is not autocommit by default. So you must commit to save # your changes. connection.commit() with connection.cursor() as cursor: # Read a single record sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s" cursor.execute(sql, ('webmaster@python.org',)) result = cursor.fetchone() print(result)

Output

{'id': 1, 'password': 'very-secret'} Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

Python Interpreter

Solution 3 – Installing PyMySQL inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the PyMySQL module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment py -3 -m venv venv # Activate the virtual environment (windows command) venv\Scripts\activate.bat # Activate the virtual environment (windows powershell) venv\Scripts\Activate.ps1 # Activate the virtual environment (Linux) source venv/bin/activate # Install PyMySQL inside the virtual environment pip install PyMySQL Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as pymysql.py as it may shadow the original PyMySQL module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘pymysql’ error occurs when we try to import the ‘PyMySQL‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the PyMySQL module by running the pip install PyMySQL command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Categories: FLOSS Project Planets

ItsMyCode: ModuleNotFoundError: No module named &#8216;pygame&#8217;

Planet Python - Sat, 2022-08-06 15:51

In Python, ModuleNotFoundError: No module named ‘pygame’ error occurs if we try to import the ‘pygame‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the pygame module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘pygame’ error.  

What is ModuleNotFoundError: No module named ‘pygame’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘pygame’ error

  • Trying to use the module- without installing the pygame package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the pygame module is not installed inside a virtual environment
  • Installing the pygame package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(pygame)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘pygame’?

pygame is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

pygame is a free and open-source cross-platform library for the development of multimedia applications like video games using Python. It uses the Simple DirectMedia Layer library and several other popular libraries to abstract the most common functions, making writing these programs a more intuitive task.

We can fix the error by installing the ‘pygame‘ module by running the pip install pygame command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: pygame.

pip show pygame

Output

Name: pygame Version: 2.1.2 Summary: Python Game Development Home-page: https://www.pygame.org Author: A community project. Author-email: pygame@pygame.org License: LGPL Location: c:\personal\ijs\python_samples\venv\lib\site-packages Solution 1 – Installing and using the pygame module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the pygame module.

# If you are using Python 2 (Windows) pip install pygame # if you are using Python 3 (Windows) pip3 install pygame # If the pip is not set as environment varibale PATH python -m pip install pygame # If you are using Python 2 (Linux) sudo pip install pygame # if you are using Python 3 (Linux) sudo pip3 install pygame # In case if you have to easy_install sudo easy_install -U pygame # On Centos yum install pygame # On Ubuntu sudo apt-get install pygame # If you are installing it in Anaconda conda install -c cogsci pygame

Once you have installed the pygame module, we can now import it inside our code and use it as shown below.

import pygame successes, failures = pygame.init() print("{0} successes and {1} failures".format(successes, failures))

Output

pygame 2.1.2 (SDL 2.0.18, Python 3.10.0) Hello from the pygame community. https://www.pygame.org/contribute.html 5 successes and 0 failures Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

Python Interpreter

Solution 3 – Installing pygame inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the pygame module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment py -3 -m venv venv # Activate the virtual environment (windows command) venv\Scripts\activate.bat # Activate the virtual environment (windows powershell) venv\Scripts\Activate.ps1 # Activate the virtual environment (Linux) source venv/bin/activate # Install pygame inside the virtual environment pip install pygame Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as pygame.py as it may shadow the original pygame module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘pygame’ error occurs when we try to import the ‘pygame‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the pygame module by running the pip install pygame command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Categories: FLOSS Project Planets

ItsMyCode: ModuleNotFoundError: No module named &#8216;pyautogui&#8217;

Planet Python - Sat, 2022-08-06 15:51

In Python, ModuleNotFoundError: No module named ‘pyautogui’ error occurs if we try to import the ‘pyautogui‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the pyautogui module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘pyautogui’ error.  

What is ModuleNotFoundError: No module named ‘pyautogui’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘pyautogui’ error

  • Trying to use the module- without installing the pyautogui package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the pyautogui module is not installed inside a virtual environment
  • Installing the pyautogui package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(pyautogui)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘pyautogui’?

pyautogui is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

PyAutoGUI is a cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.

We can fix the error by installing the ‘pyautogui‘ module by running the pip install pyautogui command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: pyautogui.

pip show pyautogui

Output

Name: PyAutoGUI Version: 0.9.53 Summary: PyAutoGUI lets Python control the mouse and keyboard, and other GUI automation tasks. For Windows, macOS, and Linux, on Python 3 and 2. Home-page: https://github.com/asweigart/pyautogui Author: Al Sweigart Author-email: al@inventwithpython.com License: BSD Location: c:\personal\ijs\python_samples\venv\lib\site-packages Requires: pymsgbox, PyTweening, pyscreeze, pygetwindow, mouseinfo Solution 1 – Installing and using the pyautogui module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the pyautogui module.

# If you are using Python 2 (Windows) pip install pyautogui # if you are using Python 3 (Windows) pip3 install pyautogui # If the pip is not set as environment varibale PATH python -m pip install pyautogui # If you are using Python 2 (Linux) sudo pip install pyautogui # if you are using Python 3 (Linux) sudo pip3 install pyautogui # In case if you have to easy_install sudo easy_install -U pyautogui # On Centos yum install pyautogui # On Ubuntu sudo apt-get install pyautogui # If you are installing it in Anaconda conda install -c conda-forge pyautogui

Once you have installed the pyautogui module, we can now import it inside our code and use it as shown below.

import pyautogui screenWidth, screenHeight = pyautogui.size() print(screenWidth, screenHeight)

Output

1920 1080 Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

Python Interpreter

Solution 3 – Installing pyautogui inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the pyautogui module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment py -3 -m venv venv # Activate the virtual environment (windows command) venv\Scripts\activate.bat # Activate the virtual environment (windows powershell) venv\Scripts\Activate.ps1 # Activate the virtual environment (Linux) source venv/bin/activate # Install pyautogui inside the virtual environment pip install pyautogui Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as pyautogui.py as it may shadow the original pyautogui module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘pyautogui’ error occurs when we try to import the ‘pyautogui‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the pyautogui module by running the pip install pyautogui command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Categories: FLOSS Project Planets

ItsMyCode: ModuleNotFoundError: No module named &#8216;PIL&#8217;

Planet Python - Sat, 2022-08-06 15:10

In Python, ModuleNotFoundError: No module named ‘PIL’ error occurs if we try to import the ‘Pillow‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the Pillow module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘PIL’ error.  

What is ModuleNotFoundError: No module named ‘PIL’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘PIL’ error

  • Trying to use the module- without installing the Pillow package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the Pillow module is not installed inside a virtual environment
  • Installing the Pillow package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(Pillow)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘PIL’?

Pillow is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

Pillow is the Python Imaging Library adds image processing capabilities to your Python interpreter. This library provides extensive file format support, an efficient internal representation, and fairly powerful image processing capabilities.

The core image library is designed for fast access to data stored in a few basic pixel formats. It should provide a solid foundation for a general image processing tool.

We can fix the error by installing the ‘Pillow‘ module by running the pip install Pillow command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: Pillow.

pip show Pillow

Output

Name: Pillow Version: 9.2.0 Summary: Python Imaging Library (Fork) Home-page: https://python-pillow.org Author: Alex Clark (PIL Fork Author) Author-email: aclark@python-pillow.org License: HPND Location: c:\personal\ijs\python_samples\venv\lib\site-packages Requires: Required-by: matplotlib Solution 1 – Installing and using the Pillow module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the Pillow module.

# If you are using Python 2 (Windows) pip install Pillow # if you are using Python 3 (Windows) pip3 install Pillow # If the pip is not set as environment varibale PATH python -m pip install Pillow # If you are using Python 2 (Linux) sudo pip install Pillow # if you are using Python 3 (Linux) sudo pip3 install Pillow # In case if you have to easy_install sudo easy_install -U Pillow # On Centos yum install Pillow # On Ubuntu sudo apt-get install Pillow # If you are installing it in Anaconda conda install -c anaconda pillow

Once you have installed the Pillow module, we can now import it inside our code and use it as shown below.

from PIL import Image img = Image.open("C:\\test.png") print(img.format, img.size, img.mode)

Output

PNG (1640, 924) RGBA Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

Python Interpreter

Solution 3 – Installing Pillow inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the Pillow module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment py -3 -m venv venv # Activate the virtual environment (windows command) venv\Scripts\activate.bat # Activate the virtual environment (windows powershell) venv\Scripts\Activate.ps1 # Activate the virtual environment (Linux) source venv/bin/activate # Install Pillow inside the virtual environment pip install Pillow Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as PIL.py as it may shadow the original Pillow module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘PIL’ error occurs when we try to import the ‘Pillow‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the Pillow module by running the pip install Pillow command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Categories: FLOSS Project Planets

James Oakley: Keeping track of upstream security issues

Planet Drupal - Sat, 2022-08-06 15:08

Drupal no longer releases a new version of Core when an upstream dependency fixes a security vulnerability. It is the responsibility of site maintainers to keep track of security advisories for all such dependent libraries. That is no small task, and a way to automate this is needed. This post looks into how this can be done.

Blog Category: Drupal Planet
Categories: FLOSS Project Planets

ItsMyCode: ModuleNotFoundError: No module named &#8216;pandas&#8217;

Planet Python - Sat, 2022-08-06 15:06

In Python, ModuleNotFoundError: No module named ‘pandas’ error occurs if we try to import the ‘pandas‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the pandas module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘pandas’ error.  

What is ModuleNotFoundError: No module named ‘pandas’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘pandas’ error

  • Trying to use the module- without installing the pandas package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the pandas module is not installed inside a virtual environment
  • Installing the pandas package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(pandas)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘pandas’?

pandas is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

pandas is a fast, powerful, flexible and easy to use open source data analysis and manipulation tool, built on top of the Python programming language.

We can fix the error by installing the ‘pandas‘ module by running the pip install pandas command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: pandas.

pip show pandas

Output

Name: pandas Version: 1.4.3 Summary: Powerful data structures for data analysis, time series, and statistics Home-page: https://pandas.pydata.org Author: The Pandas Development Team Author-email: pandas-dev@python.org License: BSD-3-Clause Location: c:\personal\ijs\python_samples\venv\lib\site-packages Requires: numpy, pytz, python-dateutil Solution 1 – Installing and using the pandas module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the pandas module.

# If you are using Python 2 (Windows) pip install pandas # if you are using Python 3 (Windows) pip3 install pandas # If the pip is not set as environment varibale PATH python -m pip install pandas # If you are using Python 2 (Linux) sudo pip install pandas # if you are using Python 3 (Linux) sudo pip3 install pandas # In case if you have to easy_install sudo easy_install -U pandas # On Centos yum install pandas # On Ubuntu sudo apt-get install pandas # If you are installing it in Anaconda conda install -c anaconda pandas

Once you have installed the pandas module, we can now import it inside our code and use it as shown below.

import pandas as pd df = pd.DataFrame( { "Name": [ "Chandler Bing", "Tom Hanks", "Will Smith", ], "Age": [22, 35, 58], "Gender": ["male", "male", "male"], } ) print(df)

Output

Name Age Gender 0 Chandler Bing 22 male 1 Tom Hanks 35 male 2 Will Smith 58 male Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

Python Interpreter

Solution 3 – Installing pandas inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the pandas module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment py -3 -m venv venv # Activate the virtual environment (windows command) venv\Scripts\activate.bat # Activate the virtual environment (windows powershell) venv\Scripts\Activate.ps1 # Activate the virtual environment (Linux) source venv/bin/activate # Install pandas inside the virtual environment pip install pandas Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as pandas.py as it may shadow the original pandas module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘pandas’ error occurs when we try to import the ‘pandas‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the pandas module by running the pip install pandas command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Categories: FLOSS Project Planets

ItsMyCode: ModuleNotFoundError: No module named &#8216;OpenSSL&#8217;

Planet Python - Sat, 2022-08-06 15:02

In Python, ModuleNotFoundError: No module named ‘openssl’ error occurs if we try to import the ‘pyOpenSSL‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the pyOpenSSL module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘openssl’ error.  

What is ModuleNotFoundError: No module named ‘openssl’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘openssl’ error

  • Trying to use the module- without installing the pyOpenSSL package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the pyOpenSSL module is not installed inside a virtual environment
  • Installing the pyOpenSSL package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(pyOpenSSL)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘openssl’?

pyOpenSSL is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

pyOpenSSL is a rather thin wrapper around (a subset of) the OpenSSL library. With thin wrapper we mean that a lot of the object methods do nothing more than calling a corresponding function in the OpenSSL library.

We can fix the error by installing the ‘pyOpenSSL‘ module by running the pip install pyOpenSSL command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: pyOpenSSL.

pip show pyOpenSSL

Output

Name: pyOpenSSL Version: 22.0.0 Summary: Python wrapper module around the OpenSSL library Home-page: https://pyopenssl.org/ Author: The pyOpenSSL developers Author-email: cryptography-dev@python.org License: Apache License, Version 2.0 Location: c:\personal\ijs\python_samples\venv\lib\site-packages Requires: cryptography Solution 1 – Installing and using the pyOpenSSL module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the pyOpenSSL module.

# If you are using Python 2 (Windows) pip install pyOpenSSL # if you are using Python 3 (Windows) pip3 install pyOpenSSL # If the pip is not set as environment varibale PATH python -m pip install pyOpenSSL # If you are using Python 2 (Linux) sudo pip install pyOpenSSL # if you are using Python 3 (Linux) sudo pip3 install pyOpenSSL # In case if you have to easy_install sudo easy_install -U pyOpenSSL # On Centos yum install pyOpenSSL # On Ubuntu sudo apt-get install pyOpenSSL # If you are installing it in Anaconda conda install -c anaconda pyopenssl

Once you have installed the pyOpenSSL module, we can now import it inside our code and use it as shown below.

Note: The OpenSSL is case sensitive and it should not be misspelled while importing in the code. from OpenSSL import crypto import os file_path = os.path.join(os.getcwd(), "/certificates/alice.crt") f = open(file_path, "r") cert = f.read() pub_key_obj = crypto.load_certificate(crypto.FILETYPE_PEM, cert).get_pubkey() pub_key = crypto.dump_publickey(crypto.FILETYPE_PEM, pub_key_obj) print(pub_key)

Output

b'-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA3W29+ID6194bH6ejLrIC\n4hb2Ugo8v6ZC+Mrck2dNYMNPjcOKABvxxEtBamnSaeU/IY7FC/giN622LEtV/3oD\ncrua0+yWuVafyxmZyTKUb4/GUgafRQPf/eiX9urWurtIK7XgNGFNUjYPq4dSJQPP\nhwCHE/LKAykWnZBXRrX0Dq4XyApNku0IpjIjEXH+8ixE12wH8wt7DEvdO7T3N3Cf\nUbaITl1qBX+Nm2Z6q4Ag/u5rl8NJfXg71ZmXA3XOj7zFvpyapRIZcPmkvZYn7SMC\np8dXyXHPdpSiIWL2uB3KiO4JrUYvt2GzLBUThp+lNSZaZ/Q3yOaAAUkOx+1h0828\n5Pi+P8lO+H2Xic4SvMq1xtLg2bNoPC5KnbRfuFPuUD2/3dSiiragJ6uYDLOyWJDi\nvKGt/72OVTEPAL9o6T2pGZrwbQuiFGrGTMZOvWMSpQtNl+tCCXlT4mWqJDRwuMGr\nI4DnnGzt3IKqNwS4Qyo9KqjMIPwnXZAmWPm3FOKe4sFwc5fpawKO01JZewDsYTDx\nVj+cwXwFxbE2yBiFz2FAHwfopwaH35p3C6lkcgP2k/zgAlnBluzACUI+MKJ/G0gv\n/uAhj1OHJQ3L6kn1SpvQ41/ueBjlunExqQSYD7GtZ1Kg8uOcq2r+WISE3Qc9MpQF\nFkUVllmgWGwYDuN3Zsez95kCAwEAAQ==\n-----END PUBLIC KEY-----\n' Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

Python Interpreter

Solution 3 – Installing pyOpenSSL inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the pyOpenSSL module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment py -3 -m venv venv # Activate the virtual environment (windows command) venv\Scripts\activate.bat # Activate the virtual environment (windows powershell) venv\Scripts\Activate.ps1 # Activate the virtual environment (Linux) source venv/bin/activate # Install pyOpenSSL inside the virtual environment pip install pyOpenSSL Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as OpenSSL.py as it may shadow the original pyOpenSSL module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘openssl’ error occurs when we try to import the ‘pyOpenSSL‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the pyOpenSSL module by running the pip install pyOpenSSL command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Categories: FLOSS Project Planets

ItsMyCode: ModuleNotFoundError: No module named &#8216;openpyxl&#8217;

Planet Python - Sat, 2022-08-06 14:46

In Python, ModuleNotFoundError: No module named ‘openpyxl’ error occurs if we try to import the ‘openpyxl‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the openpyxl module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘openpyxl’ error.  

What is ModuleNotFoundError: No module named ‘openpyxl’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘openpyxl’ error

  • Trying to use the module- without installing the openpyxl package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the openpyxl module is not installed inside a virtual environment
  • Installing the openpyxl package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(openpyxl)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘openpyxl’?

openpyxl is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

openpyxl is a Python library to read/write Excel 2010 xlsx/xlsm/xltx/xltm files. It was born from a lack of an existing library to read/write natively from Python in the Office Open XML format.

We can fix the error by installing the ‘openpyxl‘ module by running the pip install openpyxl command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: openpyxl.

pip show openpyxl

Output

Name: openpyxl Version: 3.0.10 Summary: A Python library to read/write Excel 2010 xlsx/xlsm files Home-page: https://openpyxl.readthedocs.io Author: See AUTHORS Author-email: charlie.clark@clark-consulting.eu License: MIT Location: c:\personal\ijs\python_samples\venv\lib\site-packages Requires: et-xmlfile Solution 1 – Installing and using the openpyxl module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the openpyxl module.

# If you are using Python 2 (Windows) pip install openpyxl # if you are using Python 3 (Windows) pip3 install openpyxl # If the pip is not set as environment varibale PATH python -m pip install openpyxl # If you are using Python 2 (Linux) sudo pip install openpyxl # if you are using Python 3 (Linux) sudo pip3 install openpyxl # In case if you have to easy_install sudo easy_install -U openpyxl # On Centos yum install openpyxl # On Ubuntu sudo apt-get install openpyxl # If you are installing it in Anaconda conda install -c anaconda openpyxl

Once you have installed the openpyxl module, we can now import it inside our code and use it as shown below.

from openpyxl import Workbook wb = Workbook() # grab the active worksheet ws = wb.active # Data can be assigned directly to cells ws['A1'] = 42 # Rows can also be appended ws.append([1, 2, 3]) # Python types will automatically be converted import datetime ws['A2'] = datetime.datetime.now() # Save the file wb.save("sample.xlsx") Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

Python Interpreter

Solution 3 – Installing openpyxl inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the openpyxl module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment py -3 -m venv venv # Activate the virtual environment (windows command) venv\Scripts\activate.bat # Activate the virtual environment (windows powershell) venv\Scripts\Activate.ps1 # Activate the virtual environment (Linux) source venv/bin/activate # Install openpyxl inside the virtual environment pip install openpyxl Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as openpyxl.py as it may shadow the original openpyxl module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘openpyxl’ error occurs when we try to import the ‘openpyxl‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the openpyxl module by running the pip install openpyxl command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Categories: FLOSS Project Planets

ItsMyCode: ModuleNotFoundError: No module named &#8216;numpy&#8217;

Planet Python - Sat, 2022-08-06 14:42

In Python, ModuleNotFoundError: No module named ‘numpy’ error occurs if we try to import the ‘numpy‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the numpy module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘numpy’ error.  

What is ModuleNotFoundError: No module named ‘numpy’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘numpy’ error

  • Trying to use the module- without installing the numpy package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the numpy module is not installed inside a virtual environment
  • Installing the numpy package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(numpy)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘numpy’?

numpy is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

NumPy brings the computational power of languages like C and Fortran to Python, a language much easier to learn and use. With this power comes simplicity: a solution in NumPy is often clear and elegant.

We can fix the error by installing the ‘numpy‘ module by running the pip install numpy command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: numpy.

pip show numpy

Output

Name: numpy Version: 1.23.1 Summary: NumPy is the fundamental package for array computing with Python. Home-page: https://www.numpy.org Author: Travis E. Oliphant et al. Author-email: License: BSD Location: c:\personal\ijs\python_samples\venv\lib\site-packages Requires: Required-by: scipy, pandas, opencv-python, matplotlib, biopython Solution 1 – Installing and using the numpy module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the numpy module.

# If you are using Python 2 (Windows) pip install numpy # if you are using Python 3 (Windows) pip3 install numpy # If the pip is not set as environment varibale PATH python -m pip install numpy # If you are using Python 2 (Linux) sudo pip install numpy # if you are using Python 3 (Linux) sudo pip3 install numpy # In case if you have to easy_install sudo easy_install -U numpy # On Centos yum install numpy # On Ubuntu sudo apt-get install numpy # If you are installing it in Anaconda conda install -c anaconda numpy

Once you have installed the numpy module, we can now import it inside our code and use it as shown below.

import numpy as np arr = np.array([(1,2,3)]) print("DataType is of type ", arr.dtype)

Output

DataType is of type int32 Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

Python Interpreter

Solution 3 – Installing numpy inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the numpy module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment py -3 -m venv venv # Activate the virtual environment (windows command) venv\Scripts\activate.bat # Activate the virtual environment (windows powershell) venv\Scripts\Activate.ps1 # Activate the virtual environment (Linux) source venv/bin/activate # Install numpy inside the virtual environment pip install numpy Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as numpy.py as it may shadow the original numpy module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘numpy’ error occurs when we try to import the ‘numpy‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the numpy module by running the pip install numpy command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Categories: FLOSS Project Planets

ItsMyCode: ModuleNotFoundError: No module named &#8216;nltk&#8217;

Planet Python - Sat, 2022-08-06 14:37

In Python, ModuleNotFoundError: No module named ‘nltk’ error occurs if we try to import the ‘nltk‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the nltk module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘nltk’ error.  

What is ModuleNotFoundError: No module named ‘nltk’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘nltk’ error

  • Trying to use the module- without installing the nltk package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the nltk module is not installed inside a virtual environment
  • Installing the nltk package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(nltk)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘nltk’?

nltk is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

NLTK is a leading platform for building Python programs to work with human language data. It provides easy-to-use interfaces to over 50 corpora and lexical resources such as WordNet, along with a suite of text processing libraries for classification, tokenization, stemming, tagging, parsing, and semantic reasoning, wrappers for industrial-strength NLP libraries, and an active discussion forum.

We can fix the error by installing the ‘nltk‘ module by running the pip install nltk command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: nltk.

pip show nltk

Output

Name: nltk Version: 3.7 Summary: Natural Language Toolkit Home-page: https://www.nltk.org/ Author: NLTK Team Author-email: nltk.team@gmail.com License: Apache License, Version 2.0 Location: c:\personal\ijs\python_samples\venv\lib\site-packages Requires: tqdm, joblib, regex, click Solution 1 – Installing and using the nltk module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the nltk module.

# If you are using Python 2 (Windows) pip install nltk # if you are using Python 3 (Windows) pip3 install nltk # If the pip is not set as environment varibale PATH python -m pip install nltk # If you are using Python 2 (Linux) sudo pip install nltk # if you are using Python 3 (Linux) sudo pip3 install nltk # In case if you have to easy_install sudo easy_install -U nltk # On Centos yum install nltk # On Ubuntu sudo apt-get install nltk # If you are installing it in Anaconda conda install -c anaconda nltk

Once you have installed the nltk module, we can now import it inside our code and use it as shown below.

import nltk sentence = """At eight o'clock on Thursday morning ... Arthur didn't feel very good.""" tokens = nltk.word_tokenize(sentence) print(tokens)

Output

['At', 'eight', "o'clock", 'on', 'Thursday', 'morning', 'Arthur', 'did', "n't", 'feel', 'very', 'good', '.'] Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

Python Interpreter

Solution 3 – Installing nltk inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the nltk module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment py -3 -m venv venv # Activate the virtual environment (windows command) venv\Scripts\activate.bat # Activate the virtual environment (windows powershell) venv\Scripts\Activate.ps1 # Activate the virtual environment (Linux) source venv/bin/activate # Install nltk inside the virtual environment pip install nltk Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as nltk.py as it may shadow the original nltk module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘nltk’ error occurs when we try to import the ‘nltk‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the nltk module by running the pip install nltk command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Categories: FLOSS Project Planets

Christine Lemmer-Webber: A Guile Steel smelting pot

GNU Planet! - Sat, 2022-08-06 14:35

Last month I made a blogpost titled Guile Steel: A Proposal for a Systems Lisp. It got more attention than I anticipated, which is both a blessing and and curse. I mean, mostly the former, the curse isn't so serious, it's mostly that the post was aimed at a specific community and got more coverage than that, and funny things happen when things leave their intended context.

The blessing is that real, actual progress has happened, in terms of organization, actual development (thanks to others mostly!), and a compilation of potential directions. In many ways "Guile Steel" was meant to be a meta project, somewhat biased around Guile but more so a clever name to start brewing some ideas (and gathering intelligence) around, a call-to-arms for those who are likeminded, a test even to see if there are enough likeminded people out there. The answer to that one is: yes, and there's actually a lot that's happening or has happened historically. I actually think Lisp is going through a quiet renaissance and is on the verge or a major revival, but that's a topic for another post. The goal of this post is to give a lay of the landscape, as I've seen it since then. There's a lot out there.

If you enjoy this post by the way, there's an IRC channel: #guile-steel on irc.libera.chat. It's surprisingly well populated given that people have only shown up through word of mouth.

First, an aside on language (again)

Also by-the-way, it's debatable what "systems language" even means, and the previous post spent some time debating that. Language is mostly fuzzy, and subject to the constant battle between fuzzy and crisp systems, and "systems language" is something people evoke to make themselves sound like very crispy people, even though the term could hardly be fuzzier.

We're embracing the hand-waviness here; I've previously mentioned that "Blockchain" is to "Bitcoin" what "Roguelike" is to "Rogue". Similarly, "Systems Language" is to "C/Rust" what "Roguelike" is to "Rogue".

My friend Technomancy put things about as well or as succinctly as you could: "low-level enough to bootstrap a runtime". We'll extend "runtime" to not only mean "programming language runtime" but also "operating system runtime", and that's the scope of this post.

With that, let's start diving into directions.

Carp and Scopes

I was unaware at the time of writing the previous post of two remarkable "systems lisps" that already existed, are here, now, today, and you can and maybe should use them: Carp and Scopes. Both of them are statically typed, and both perform automatic memory management without the overhead of a garbage collector or reference counting in a style familiar to Rust.

They are also both kind of similar yet different. Carp is written on top of Haskell, looks a lot like Clojure in style. Scopes is written in C++, looks a lot like Scheme, and has an optional, non-parenthetical whitespace syntax which reminds me a lot of Wisp, so is maybe more amenable to the type of people who fear parentheses or must work with people who do.

I can't make a judgement about either; I would like to find some time to try each of them. Scopes looks more up my alley of the two. If someone packaged either of these languages for Guix I would try it in a heartbeat.

Anyway, Carp and Scopes already are systems lisps of sorts you can try today. (If you've made something cool with either of them, let me know.)

Pre-Scheme

There's a lot to say on this one, despite its obscurity, enough that I'm going to give it several sub-headings. I'll get the big one up front: Andrew Whatson is doing an incredible job porting Pre-Scheme to Guile. But I'll get more to that below.

What the heck is Pre-Scheme anyway?

PreScheme (or is it Pre-Scheme or prescheme or what? nobody is consistent, and I won't be either) is a "systems lisp" that is used to bootstrap the incredible but "sleeper hit" (or shall we say "cult classic"?) of programming language runtimes, Scheme48. PreScheme compiles to C, is statically typed with type inference based on a modified version of Hindley-Milner, and uses manual memory management for heap-allocated resources (much like C) rather than garbage collection. (C is just the current main target, compiling directly to native architectures or WebAssembly is also possible.)

The wild things about PreScheme are that unlike C or Rust, you can hack on it live at the REPL just like Scheme, and you can even incorporate a certain amount of Scheme, and it mostly looks like Scheme. But it still compiles down efficiently to low-level code.

It's used to implement Scheme48's virtual machine and garbage collector, and is bootstrappable from a working Scheme48, but there's also apparently a version sitting around somewhere on top of some metacircular Scheme which Jonathan Rees wrote on top of Common Lisp, giving it a good bootstrapping story. While used for Scheme48, and usable from it today, there's no reason you can't use it for other things, and a few smaller projects have.

What's more wild about PreScheme is how incredibly good of an idea it is, how long it's sat around (since the 80s, with a lot of work happening in the 90s!), and how little attention it's gotten. PreScheme's thoughtful design actually follows from Richard Kelsey's amazing PhD dissertation, Compilation By Program Transformation, which really feels like the kind of obscure CS thing that, if you've made it this far in this writeup, you probably would love reading. (Thank you to Olin Shivers for reviving this dissertation in LaTeX, which otherwise would have been lost to history.)

guile-prescheme

Now I did mention prescheme and how I thought that was a fairly interesting starting point on the last Guile Steel blogpost, and I actually got several people reaching out to me saying they wanted to take up this initiative, and a few of them suggested maybe they should start porting PreScheme to Guile, and I said "yes you should!" to all of them, but one person took up the initiative quickly and has been doing a straight and faithful port to Guile named guile-prescheme.

The emulator (which isn't too much code really) has already worked for a couple of weeks (which means you can already hack PreScheme at Guile's REPL, and Andrew Whatson says that the "compile to C" compiler is already well on its way, and will likely be there in about a month.

The main challenge apparently is the conversion of macros, which are stuck in the r4rs era of Scheme. Andrew has been slowly converting everything to syntax-case. syntax-case is encoded in r6rs and even more appealingly r7rs-small, which begs the question: how general of a port is this? Does it really have to just be to Guile? And that brings us to our next subsection...

The Secret Society of PreScheme Revivalists

Okay there's not really a secret society, we just have an email thread going and I organized a video call recently, and we're likely to do another one (I hope). This one was really good, very productive. (We didn't record it, sadly. Maybe we should have.)

On said video call we got Andrew Whatson of course, who's doing the current porting effort, but also Richard Kelsey (the original brain behind PreScheme, co-author of much of Scheme48), Michael Sperber (current maintainer of Scheme48 and also someone who has used PreScheme previously commercially, to do some monte carlo simulation things for some financial firm or something curious like that), and Jonathan Rees (co-author of Scheme48, and one of my friends who I like to call up and talk about all sorts of curious topics). There were a few others, all cool people, and also me, hand-waving excitedly as usual.

As an aside, my wife Morgan says my superpower is that I'm good at "showing up in a room and being excited and getting everyone else excited", and she's right, I think. And... well there's just a lot of interesting stuff in computer science history, amazing people whose work has just been mostly ignored, stuff left on the shelf. It's not what the Tech Influencers (TM) are currently touting, it's not what a FAANG company is going to currently hire you to do, but if you're trying to solve the hard problems people don't even realize they have, your best bet is to scour history.

I don't know if it's true or not but this felt like one of those times where the folks who have worked on PreScheme historically seemed kind of surprised that here we had a gathering of people who are extremely interested in the stuff they've done, but also happy about it. Anyway, that seemed like my reading, I like to think so anyway. Andrew (I think?) said some nice things about how it was just exciting to be able to talk to the people who have done these things, and I agree. It is cool stuff. We are grateful to be able to talk about it.

The conversation was really nice, we got some interesting historical information (some of that which I've conveyed here), and Richard Kelsey indicated that he's been doing work on microcontrollers and wishes he could be using PreScheme, but the things clients/employers get nervous about is "will be able to actually hire anyone to work on this stuff who isn't just you?" I'd like to think that we're building up enough enthusiasm where we can demonstrate in the affirmative, but that's going to take some time.

Anyway, I hinted in the last part that some of the more interesting conversation came to, just how portable is this port? Andrew indicated that he thought that the port to Guile as he was doing it was already helping to make things more portable. Andrew is just focusing on Guile first, but is avoiding the Guile-specific ice-9 namespace of Guile modules (which in this case, from a standardization perspective, becomes a little bit too appropriate) and is using as much generic Scheme and SRFI extensions as possible. Once the Guile version gets working, the goal is then to try porting to a more standardized form of Scheme (probably r7rs-small), and then that would mean that any Scheme following that standard could use the same version of PreScheme. Michael Sperber seemed to indicate that maybe Scheme48 could use this version too.

This would actually be pretty incredible because it would mean that any version of Scheme following the Scheme standard would suddenly have access to PreScheme, and any of those could also be used to bootstrap a PreScheme based Scheme.

A PreScheme JIT?

I thought Andrew Whatson (flatwhatson here) said this well enough himself so I'm just going to quote it verbatim:

<flatwhatson> re: pre-scheme interest for bootstrapping, i think it's more interesting than just "compiling to C" <flatwhatson> Michael Sperber's rejected paper "A Tractable Native-Code Scheme System" describes repurposing the pre-scheme compiler (more accurately called the transformational compiler) as a jit byte-code optimizer and native-code emitter <flatwhatson> the prescheme compiler basically lowers prescheme code to a virtual machine-code and then emits that as C <flatwhatson> i think it would be feasible to directly emit native code at that point instead <flatwhatson> https://www.deinprogramm.de/sperber/papers/tractable-native-code-scheme-system.pdf <flatwhatson> Kelsey's dissertation describes transforming a high-level language to a low-level language, not specifically scheme to C. <flatwhatson> > The machine language is an assembly language written in the syntax of the intermediate language and has a much simpler semantics. The machine is assumed to be a Von Neumann machine with a store and register-to-register instructions. Identifiers represent the machine’s registers and primitive procedures are the machine’s instructions. <flatwhatson> Also, we have code for the unreleased byte-code jit-compiling native-emitting version of Scheme 48: https://www.s48.org/cgi-bin/hgwebdir.cgi/s48-compiler/

(How the hell that paper was rejected btw, I have no idea. It's great.)

Future directions for PreScheme

One obvious improvement to PreScheme is: compile to WebAssembly (aka WASM)! This would be pretty neat and maybe, maybe, maybe could mean a good path to getting more Schemes in the browser without using Emscripten (which is a bit heavy-handed of an approach). Andrew and I both think this is a fun idea, worth exploring. I think once the "compile to C" part of the port to Guile is done, it's worth beginning to look at in earnest.

Relatedly, it would also, I think, be pretty neat if guile-prescheme was compelling enough for more of Guile to be rewritten in it. This would improve Guile's already-better-than-most bootstrapping story and also make hacking on certain parts of Guile's internals more accessible and pleasant to a larger part of Guile's existing userbase.

The other obvious improvement to PreScheme is exploring (handwave handwave handwave) the kinds of automated memory management which have become popular with Rust's borrow checker and also appear in Carp and Scopes, as discussed above.

3L: The Computing System of the Future (???)

I mentioned that an appealing use of PreScheme might be to write not just a language runtime, but also an operating system. A very interesting project called 3L exists and is real and does just that. In fact, it's also a capability-secure operating system, and it cites all the right stuff and has all the right ideas going for it. And it's using PreScheme!

Now the problem is, seemingly nobody I know who would be interested in exactly a project like this even had heard of it before (except for the incredible and incredibly nice hacker pukkamustard is the one who made me even aware of it by mentioning it in the #guile-steel chatroom), and I couldn't even find the actual code on the main webpage. But there actually is source code, not a lot of it, but it's there, and in a way "not a lot of it" is not a bad thing here, because what's there looks stunningly similar to a very familiar metacircular evaluator, which begs the question, is that really enough, though?

And actually maybe it is, because hey look there's a demo video and a nice talk. And it's using Scheme48!

(As a complete aside: I'd be much more likely to play with Scheme48 if someone Geiser support for it... that's something I've poked at doing every now and then but I haven't had enough of a dedicated block of time. If you, dear reader, feel inspired enough to add such support, or actually if you give 3L a try, let me know).

Anyway, cool stuff, I've been meaning to reach out to the author, maybe I will after I post this. I wonder what's come of it. (It's also missing a license file or any indicators, but maybe we could get that fixed easily enough?)

WebAssembly

I had a call with someone recently who said WebAssembly was really only useful for C/Rust users, and I thought this was fairly surprising/confusing, but maybe that's because I think WebAssembly is pretty cool and have hand-coded a small amount of it for fun. Its text-based syntax is S-Expression based which makes it appealing for lispy type folks, and just easy to parse and work with in general.

It's stretching it a bit to call WebAssembly a Lisp, it's really just something that's designed to be an intermediate language (eg in GCC), a place where compiler authors often deign it okay/acceptable to use s-expressions because they don't fear that they'll scare off non-lispers or PLT people, because hey most users aren't going to touch this stuff anyway, right?

I dunno, I consider it a win at least that s-expressions have survived here. I showed up to an in-person WebAssembly meeting once and talked to one of the developers about it, praised them for this choice, and they said "Oh... yeah, well, we initially did it because it was the easiest thing to start with, and then eventually we came to like it, which I guess is the usual thing that happens with S-Expressions." (Literally true, look up the history of M-Expressions vs S-Expressions.)

At any rate, most people aren't coding WebAssembly by hand. However, you could, and if you're going to, a Lisp based environment is actually a really good choice. wasm-adventure is a really cool little demo game (try it!), all hand-written in WebAssembly kinda sorta. The README gives its motivations as "Is it possible (and enjoyable) to write a game directly in web assembly's text format? Eventually, would it be cool to generate wat from Scheme code using the Racket lang system?", and the answer becomes an emphatic "yes". What's interesting is that Lisp's venerable quasiquote does much of the heavy lifting to make, without too much work, a little DSL for authoring WebAssembly which results in some surprisingly easy to read code compared to generic WebAssembly. (The author, Zoé Martin, is another one of those quiet geniuses you run into on the internet; she has a lovely homebrew computer design too.)

So what I'd really like is to see more languages compiling directly to WebAssembly without emscripten as an intermediate hack. Guile especially, of course. Andy Wingo gave an amazing little talk on this where he does a little (quasi, pre-recorded) live coding demo of compiling to WebAssembly and I thought "YES!!! Compiling to WASM is probably right around the corner" and it turns out that's probably not the case because Wingo would like to see some important extensions to WASM land, and I guess, yes that probably makes sense, and also he's working on a new garbage collector which seems damn cool and like it'll be really good for Guile and maybe even could help the compiling to WASM story even before the much desired WASM-GC extension we all want lands, but who knows. I mean it would also be nice to have like, the tail call elimination extension, etc etc etc. But see also Wingo's writeup about targeting the web from last year, etc etc. (And on that note, I mean, is Webassembly the new Kubernetes?)

As another aside, there are two interesting Schemes which are actually written in WebAssembly, or rather, one written directly in hand-coded WASM named scheme.wasm, and one which compiles itself to Webassembly called Schism (which has a cool paper, but sadly hasn't been updated in a couple of years).

As another another aside, I was on a video call with Douglas Crockford at one point and mentioned WebAssembly and how cool I thought it was, and Crock kinda went "meh" to it, and I was like what? I mean it has ocap people you and I have both collaborated on it with, overall its design seems pretty good, better than most of the things of its ilk that have been tried before, why are you meh'ing WebAssembly? And Crock said that well, it's not that WebAssembly is bad, it's just that it felt like an opportunity to do something impactful, and it's "just another von neumann architecture", like, boring, can't we do better? But when I asked for specific alternatives, Crock didn't have a specific design in mind, just thought that maybe we could do better, maybe it could even incorporate actors at a more fundamental level.

Well... it turns out we both know someone who did just that, and (so I hear) both recently got nerdsniped by that very same person who had just such an architecture...

Mycelia and uFork

So I had a call with sorta-colleague, sorta-friend I guess? I'm talking about Dale Schumacher, and I don't know him super well, we don't get to talk that much, but I've enjoyed the amount we have. Dale has been trying to get me to have a video call for a while, we finally did, and I was expecting us to talk about our respective actor'y system projects, and we did... but the big surprise was hearing about Mycelia, Dale's ocap-secure hybrid-actor-model-lisp-machine-lambda-calculus operating system, and its equally astounding, actually maybe more astounding, virtual machine and maybe potentially CPU architecture design, uFork. We're going to take a major digression but I promise that it ties back in.

This isn't the first time Dale's reached out and it's resulted in me being surprised and nerdsniped. A few years ago Dale reached out to me to talk about this programming language he wrote called Humus. What's astounding personally about Humus is that it has an eerie amount of similarity to Spritely Goblins, the ocap distributed object architecture I've been working on the last few years, despite that we fully designed our systems independently. Dale beat me to it, but it was an independent reinvention in the sense that I simply wasn't aware of Humus until Dale started emailing me.

The eerie similarity is because I think Dale and I's systems are the most seriously true-to-form implementations of the "Classic Actor Model" that have been implemented in recent times (more true than say, Erlang, which does some other things, and "Classic" thrown on there because Carl Hewitt has some new ideas that he feels strongly should now be associated with "Actor Model" that can be layered on Dale and I's systems, but are not there at the base layer). (Actually, Goblins supports one other thing that makes it more the vat model of computation, but that isn't important for this post.) The Classic Actor Model says (hand-waving past pre-determinism in the general case, at least from the perspective of a single actor, due to ordering concerns... but those too can be layered on) that you can do pretty much all computation in terms of just actors, which are these funky distributed objects which handle messages one at a time, and while handling them are only able to do some combination of three things: (1) send messages to actors they know about, (2) create new actors (and get their address in the process, which they can share with other actors should they choose... argument passing, basically), and (3) designate their behavior for the next time they are handling a message. It's pretty common to use "become" for last that operation, but the curious thing that both Dale and I did was use lambdas as the thing you become. (By the way, those familiar with Scheme history should notice something interesting and familiar here, and for that same reason Dale and I are also in the shared company of being scolded by Carl Hewitt for saying our actors are made out of lambdas, despite him liking our systems otherwise, I think...)

I remarked off-hand that "well I guess one of the main differences between our systems, and maybe a thing you might not like, is that mine is lispy / based on Scheme, and..."

Dale waved his hand. "That's mostly surface..."

"Surface syntax, yeah I know. So I guess it doesn't..."

"No wait it does matter. What I'm trying to show you is that I actually do like that kind of stuff. In fact I have some projects which use it at a fundamental level. Here... let me show you..." And that's when we started talking about uFork, the instruction architecture he was working on, which I later found was actually part of a larger thing called Mycelia.

Well I'm glad I got the lecture directly from Dale because, let's see, how does the Mycelia project brand itself (at the time of writing)? "A bare-metal actor operating system for Raspberry Pi." Well, maybe this underwhelming self-description is why seemingly nobody I know (yes, like 3L above) has seemingly heard about it, despite it being extremely up the alley of the kind of programming people I tend to hang out with.

Mycelia is not just some throwaway raspberry pi project (which is certainly the impression I would have gotten from lazily scanning that page). Most of those are like, some cute repackaging of some existing FOSS POSIX'y thing. But Mycelia is an actually-working, you-can-actually-boot-it-on-real-hardware open source operating system (under Apache v2) with a ton of novel ideas which happens to be targeting the Raspberry Pi, but it could be ported to run on anything.

Anyway, there are a lot of interesting stuff in there, but here's a bulleted list summary. For Mycelia:

  • It's is an object-capability-secure operating system
  • It has a Lisp-like language for coding, pretty much Scheme-like, to hack around on
  • The Kernel language / Vau calculus show up, which is... wild
  • It encodes the Actor model and the Lambda calculus in a way that is sensible and coherent afaict
  • It is a "Lisp Machine" in many senses of the term.

But the uFork virtual machine / abstract idea for a CPU also are curious on their own. I dunno, I spent the other night reading it kind of wildly after our call. It also encodes the lambda calculus / actor model in fundamental instructions.

Dale was telling me he'd like to build an actual, physical CPU, but of course that takes a lot of resources, so he might settle for an FPGA for now. The architecture, should it be built, also somehow encodes a hardware garbage collector, which I haven't heard of anything doing that since the actual physical Lisp Machines died out.

At any rate, Dale was really excited to tell me about why his system encoded instructions operating on memory split in quads. He asked me why I thought that would be; I'm not honestly sharp enough in this kind of area to know, sadly, though I said "I hope it's not because you're planning on encoding RDF at the CPU layer". Thankfully it's not that, but then he started mentioning how his system encodes a stream of continuations...

Wait, that sounds familiar. "Have you ever heard of something called sectorlisp?" I asked, with a raised eyebrow.

"Scroll to the bottom of the document," Dale said, grinning.

Oh, there it was. Of course.

sectorlisp

The most technically impressive thing I think I've ever seen is John McCarthy's "Lisp implemented in Lisp", also known as a "metacircular evaluator". If you aren't familiar with it, it's been summarized well in the talk The Most Beautiful Program Ever Written by William Byrd. I think the best way to understand it really, and (I'm biased) the easiest to read version of things is in the Scheme in Scheme section of A Scheme Primer (though I wrote that for my work, and as said, I'm biased... I don't think I did anything new there, just explained ideas as simply as I could).

The second most technically impressive thing I've ever seen is sectorlisp, and the two are directly related. According to its README, "sectorlisp is a 512-byte implementation of LISP that's able to bootstrap John McCarthy's meta-circular evaluator on bare metal." Where traditional metacircular evaluator examples can be misconstrued as being the stuff of pure abstractlandia, sectorlisp gets brutally direct about things. In one sector (half a kilobyte!!!), sectorlisp manages to encode a whole-ass lisp system that actually runs. And yet, the nature of the metacircular evaluator persists. (Take that, person on Hacker News who called metacircular evaluators "cheating"! Even if you think mine was, I don't think you can accuse sectorlisp's of that.)

If you do nothing else, watch the sectorlisp blinkenlights demo, even just as an astounding visual demo alone. (Blinkenlights is another project of Justine's, and also wildly impressive.) I highly recommend the following blogposts of Justine's: SectorLISP Now Fits in One Sector, Lisp with GC in 436 bytes, and especially Lambda Calculus in 383 Bytes. Hikaru Ikuta (woodrush) has also written some amazing blogposts, including Extending SectorLISP to Implement BASIC REPLs and Games and Building a Neural Network in Pure Lisp Without Built-In Numbers Using Only Atoms and Lists (and related, but not part of sectorlisp: A Lisp Interpreter Implemented in Conway's Game of Life, which gave off strong Wireworld Computer vibes for me). If you are only going to lazily scan through one of those blogposts, I recommend it be Lambda Calculus in 383 Bytes, which has some wild representations of the ideas (including visually), a bit too advanced for me at present admittedly, though I stare at them in wonder.

I had a bunch more stuff here, partly because the author is someone I find both impressive technically but who has also said some fairly controversial things... to say the least. But I think it was too much of a digression for this article. The short version is that Justine's stuff is probably the smartest, most mind-blowing tech I've ever seen, kinda scarily and intimidatingly smart, and it's hard to mentally reconcile that with some of those statements. I don't know, maybe she wants to move past that phase, I'd like to think so. I think she hasn't said anything like that in a long time, and it feels out of phase with the rest of this post but... it feels like something that needs to be acknowledged.

GOOL, GOAL, and OpenGOAL

Every now and then when people say Lisp couldn't possibly be performant, Lisp people like to bring up that Naughty Dog famously had its own Lisp implementations for most of its earlier games. Andy Gavin has written about GOOL, which was a mix of lisp and assembly and of course lisp generating assembly, and I don't think much was written about its followup GOAL until OpenGOAL came up, which... I haven't looked at it too much tbh. I guess it's getting interesting for some people for the ability to play Jak and Daxter on modern hardware (which I've never played but looked fun), but I'm more curious if someone's gonna poke at it to do something completely different.

But I do know some of the vague legends. I don't remember if this is true or where I read it but one of them that Sony accused Naughty Dog of accessing some devkit or APIs they weren't supposed to have access to because they were pulling off a bunch of features performantly in Crash Bandicoot that were assumed otherwise not possible. But nope, just lisp nerds making DSLs that pull off some crazy shit I guess.

BONUS: Shoutout to Kandria

Oh, speaking of games written in Lisp, I guess Kandria's engine is gonna be FOSS, and that game looks wicked cool, maybe support their Kickstarter while you still can. It's not really in the theme of this post from the definition of "systems lisp" I gave earlier, but this blogpost about its lispy internals is really neat.

Okay here's everything else we're done

This was a long-ass post. There's other things maybe that could be discussed, so I'll just dump briefly:

Okay, that's it. Hopefully you found something interesting out of this post. Meanwhile, I was just gonna spend an hour on this. I spent my whole day! Eeek!

Categories: FLOSS Project Planets

ItsMyCode: ModuleNotFoundError: No module named &#8216;mysql&#8217;

Planet Python - Sat, 2022-08-06 14:25

In Python, ModuleNotFoundError: No module named ‘mysql’ error occurs if we try to import the ‘mysql-connector-python‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the mysql-connector-python module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘mysql’ error.  

What is ModuleNotFoundError: No module named ‘mysql’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘mysql’ error

  • Trying to use the module- without installing the mysql-connector-python package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the mysql-connector-python module is not installed inside a virtual environment
  • Installing the mysql-connector-python package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(mysql-connector-python)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘mysql’?

mysql-connector-python is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

MySQL Connector enables Python programs to access MySQL databases, using an API that is compliant with the Python Database API Specification v2.0 (PEP 249). It also contains an implementation of the X DevAPI, an Application Programming Interface for working with the MySQL Document Store.

We can fix the error by installing the ‘mysql-connector-python‘ module by running the pip install mysql-connector-python command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: mysql-connector-python.

pip show mysql-connector-python

Output

Name: mysql-connector-python Version: 8.0.30 Summary: MySQL driver written in Python Home-page: http://dev.mysql.com/doc/connector-python/en/index.html Author: Oracle and/or its affiliates Author-email: License: GNU GPLv2 (with FOSS License Exception) Location: c:\personal\ijs\python_samples\venv\lib\site-packages Requires: protobuf Solution 1 – Installing and using the mysql-connector-python module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the mysql-connector-python module.

# If you are using Python 2 (Windows) pip install mysql-connector-python # if you are using Python 3 (Windows) pip3 install mysql-connector-python # If the pip is not set as environment varibale PATH python -m pip install mysql-connector-python # If you are using Python 2 (Linux) sudo pip install mysql-connector-python # if you are using Python 3 (Linux) sudo pip3 install mysql-connector-python # In case if you have to easy_install sudo easy_install -U mysql-connector-python # On Centos yum install mysql-connector-python # On Ubuntu sudo apt-get install mysql-connector-python # If you are installing it in Anaconda conda install -c anaconda mysql-connector-python

Once you have installed the mysql-connector-python module, we can now import it inside our code and use it as shown below.

import mysql.connector # Connect to server cnx = mysql.connector.connect( host="127.0.0.1", port=3306, user="mike", password="s3cre3t!") # Get a cursor cur = cnx.cursor() # Execute a query cur.execute("SELECT CURDATE()") # Fetch one result row = cur.fetchone() print("Current date is: {0}".format(row[0])) # Close connection cnx.close() Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

Python Interpreter

Solution 3 – Installing mysql-connector-python inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the mysql-connector-python module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment py -3 -m venv venv # Activate the virtual environment (windows command) venv\Scripts\activate.bat # Activate the virtual environment (windows powershell) venv\Scripts\Activate.ps1 # Activate the virtual environment (Linux) source venv/bin/activate # Install mysql-connector-python inside the virtual environment pip install mysql-connector-python Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as mysql.py as it may shadow the original mysql-connector-python module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘mysql’ error occurs when we try to import the ‘mysql-connector-python‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the mysql-connector-python module by running the pip install mysql-connector-python command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Categories: FLOSS Project Planets

C++17’s {} impeding SC for new method overloads

Planet KDE - Sat, 2022-08-06 10:14

Are you the C++ experienced reader to solve the following challenge?

Given a class C (edit: covered by binary compatibility needs) with the overloaded methods foo() and foo(A a):

class C { public: void foo(); void foo(A a); };

Now you want to add an overload, to serve further use-cases as requested by API consumers, and going for another overload matches your API guidelines :

        void foo(B b);

But there is existing consumer code, making use of C++17, which calls

    C c;     c.foo({});

So the new overload will not be source-compatible and break existing code, due to the ambiguity whether {} should be turned into an instance of A or B.

What could be done about this?

The goals here would be:

  1. to enable API consumers to write code which works as if there are the two old and the one new overloads declared
  2. any calls using the {} expression as argument are resolved to a method which emits a compiler warning to avoid that ambiguous argument and which on any next compatibility breaking occasion can be simply removed

While asking around, some approaches have been proposed, but so far none could satisfy the second goal, catching existing ambiguous argument expressions to hint API consumers to adapt them.

Would you have an idea?

Edit: Note that we cannot change A or B (might be types/classes from elsewhere), and only can add new API to C, due to binary compatibility needs.

Edit: On a second thought, similar problems also exist before C++17 already when an argument has a type which can be implicitly converted both to A and B, by implicit constructors or type operator methods.

Categories: FLOSS Project Planets

ItsMyCode: [Solved] RuntimeWarning: invalid value encountered in double_scalars

Planet Python - Sat, 2022-08-06 08:40

The RuntimeWarning: invalid value encountered in double_scalars mainly occurs when you perform a complex mathematical operation using NumPy that involves extremely small or very large numbers and also if we pass an invalid input such as NaN or null while performing NumPy operations.

In this tutorial, we will look at RuntimeWarning: invalid value encountered in double_scalars and how to resolve this error with examples.

What is RuntimeWarning: invalid value encountered in double_scalars?

We get the RuntimeWarning while performing the complex math operation with very large or extremely small numbers using NumPy.  

Few libraries in Python cannot handle such complex numbers and raise RuntimeWarning: invalid value encountered in double_scalars

Let us take a simple example to reproduce this error. In the below example, we have two NumPy arrays performing the Mathematical operations.

import numpy as np # define two NumPy arrays arr1 = np.array([[1000, 1100]]) arr2 = np.array([[1200, 3000]]) # Complex mathematical operation result = np.exp(-3*arr1).sum() / np.exp(-3*arr1).sum() print(result)

Output

RuntimeWarning: invalid value encountered in double_scalars

We receive a RuntimeWarning because the denominator is a complex number and extremely small that is closer to zero.

Hence when we perform the division with an extremely small denominator, we will get a large complex number as an output that Python cannot handle and raises a RuntimeWarning

Fix – RuntimeWarning: invalid value encountered in double_scalars

Since NumPy cannot handle large complex numbers, we can fix the error by using a special function logsumexp() from another library, SciPy.

The SciPy is a scientific computation library that uses NumPy underneath. SciPy stands for Scientific Python. The library is designed to handle such complex scientific scenarios.

The logsumexp() method can handle large and small complex numbers with exponents efficiently.

Let us modify our code to use the logsumexp() method from the SciPy library.

import numpy as np from scipy.special import logsumexp # define two NumPy arrays arr1 = np.array([[1000, 1100]]) arr2 = np.array([[1200, 3000]]) # Complex mathematical operation result = np.exp(logsumexp(-3 * arr1) - logsumexp(-3 * arr2)) print(result)

Output

3.7730203009299397e+260

Notice that the output is extremely large 3.7730203009299397e+260. Still, we did not receive any error because we have used the special logsumexp() method from the SciPy library that is designed to handle such scientific numbers.

Conclusion

The RuntimeWarning: invalid value encountered in double_scalars mainly occurs when you perform a complex mathematical operation that results in extremely large or small numbers and also if we pass an invalid input such as NaN or null while performing NumPy operations.

We can resolve the error by using a special method logsumexp() from the SciPy library that is designed to handle such scientific numbers and complex operations.

Categories: FLOSS Project Planets

IslandT: Move the image across the screen with Pygame

Planet Python - Sat, 2022-08-06 08:27

In this chapter, I am going to show you a simple python program that will move the image across the screen by clicking and then dragging it within the screen. While the image is in the dragging state I will make it semi-opaque. The game plan here is to set a few flags and basically make the image follow our mouse cursor.

Below is the entire code, why don’t you try it yourself?

# Import and initialize the pygame library import pygame pygame.display.init() # set the caption on the panel pygame.display.set_caption("Draw Some Drawing") # windows height and width windowwidth = 600 windowheight = 600 # Print this line on output panel if the initialize process is successful if(pygame.display.get_init() == True): print("Success initialize the game!") # Initialize a window or screen for display screen = pygame.display.set_mode([windowwidth, windowheight]) # Print the x, y size of the game display window print("The windows size is " + str(pygame.display.get_window_size())) circle_center_x = 300 # set the circle initial coordinates, set its radius as well circle_center_y = 300 circle_radius = 60 # set the mouse press coordinates mouse_press = False mouse_coordinate_x = 0 mouse_coordinate_y = 0 # hat image load pawn0 = pygame.image.load("pawn.png") width, height = pawn0.get_size() # return width and height of the hat # the initial position of the hat image original_image_x = circle_center_x-width/2 original_image_y = circle_center_y-circle_radius-height # Run the game until the user asks to quit running = True while running: # If the user clicks on the 'x' button on pygame display window then set running to false for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Fill the rectangles with blue color screen.fill((0,0,255)) # check the left mouse button press state left_mouse_button_press_state = pygame.mouse.get_pressed(num_buttons=3)[0] if (left_mouse_button_press_state == True and mouse_press == False): mouse_coordinate_x, mouse_coordinate_y = pygame.mouse.get_pos() if (mouse_coordinate_x >= original_image_x and mouse_coordinate_x <= original_image_x + width and mouse_coordinate_y >= original_image_y and mouse_coordinate_y <= original_image_y + height): mouse_press = True elif (left_mouse_button_press_state == True and mouse_press == True): original_image_x, original_image_y = pygame.mouse.get_pos() pawn0.set_alpha(100) elif (left_mouse_button_press_state == False and mouse_press == True): mouse_press = False original_image_x, original_image_y = pygame.mouse.get_pos() pawn0.set_alpha(255) pygame.draw.circle(screen, pygame.Color(255,255,255), (circle_center_y, circle_center_y), circle_radius) # Draw white circle at the middle of screen screen.blit(pawn0, (original_image_x, original_image_y)) # drawing the hat pygame.display.flip() # refresh the display screen # Quit the game pygame.display.quit()

Here are a few outcomes, you can do it better by slightly adjusting the mathematical part of the equation!

Now it is time for me to get back to continue research on Pygame!

Categories: FLOSS Project Planets

Pages