I would like to combine the file counties output by pip install MySQLdb-t into one file and read them by import.(Image like import mysql.MySQLdb.)

Asked 2 years ago, Updated 2 years ago, 95 views

$pipe install MySQLdb-t.

Files around MySQL printed in ↑

mysql/
in the directory
I want to be able to read the package? (library) in import.

This is the image.

-- --mysql
│ -- -- MySQL_python-1.2.5.eg-info
│ │ PK -- PKG-INFO
│ │ S -- SOURCES.txt
│ │ d -- dependency_links.txt
│ │ in -- installed-files.txt
│ │ --top_level.txt
│ -- -- MySQLdb
│ │ < --init.py
│ │ -- --init.pyc
│ │ -- -- connections.py
│ │ con -- connections.pyc
│ │ con --constants
│ ││ -- -- CLIENT.py
│ │ CL -- CLIENT.pyc
│ ││ -- -- CR.py

You can't just say pip install MySQLdb, but by specification you have to find a way to spit files into the directory.

In addition to spitting out to the current directory, the reason why I put it in a directory called mysql is because
This is because it is more convenient to organize it when using it for other projects.
(I would like to reuse it in one independent form like a module.)

Under these circumstances, trying to import is not working.

import mysql.MySQLdb
Traceback (most recent call last):
File", line 1, in
ImportError: No module named MySQLdb

I don't know if I can do this in the first place, so I'm looking into various things.
I asked you a question because I couldn't come across the article you were looking for.

Thank you for your cooperation.

python pip

2022-09-29 22:06

1 Answers

First, under mysql, add the file _init__.py.The contents can be empty.
This is required for mysql to be recognized as a module.

Then add mysql to the search path.

import sys
sys.path.append('mysql')

If the current directory is different, change the 'mysql' as appropriate or specify it in the absolute path.

See also:
Python Tutorial-6.4.Package


2022-09-29 22:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.