This is a script that simply takes an example CSV file an imports it into SQL Server using pandas with Python. The table is created automatically if it does not already exist.
Install Anaconda
Install Powershell 7
Open the Anaconda terminal and run
conda init powershell
Open Powershell and check that it is version 7
$PSVersionTable
Download conda installation script and run it
curl -O https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-x86_64.sh
bash Anaconda3-2023.09-0-Linux-x86_64.sh
source ~/.bashrc
Create Python Environment with Python 3.12
conda create -n py3.12 python=3.12 anaconda
Activate the environment
conda activate py3.12
Install the requirements
pip install -r requirements.txt
Ensure you have set the variables in the script as neccessary
_server = 'TestServer'
_database = 'MyTestDB'
_table_name = 'TestCSV'
_username = None
_password = None
file_path = 'test.csv'
Run the program (Windows)
python .\importer.py
OR
Run the program (Linux)
chmod +x importer.py
./importer.py