My program is developed using a virtual environment in VSCode.
Before launching python main.py in VSCode I activate the venv.
Inside the program I use:
if not which(’mysql’) :
print('not installed')
to check the mysql server is installled. With mysql installed it prints
“not installed”
Using python in a terminal outside of venv with
>>>from shutil import which
>>>which('mysql')
it returns the path to the installed mysql (in my case
This isn’t a reliable way to test if a mysql server is installed. What you’re testing for there is the MySQL CLI client, which is completely independent. The server doesn’t need to be on PATH, since it’s not something an app normally needs to invoke.
It depends on what you’re trying to achieve. If I want to see if there’s a MySQL server running, I would just try to connect to it; being installed is usually irrelevant.
It’s a relevant question. I just want to inform the user that they forgot to install the server. I am aware I could just try the connection but in this case I would not see what the reason is,server not installed, wrong database name or wrong password…
Might be relevant here, the shutil tests are failing for me in vscode’s terminal but work in the regular Mac OS terminal with the same configs and without using any venvs:
e@Edwards-MacBook-Pro cpython % ./python.exe -m test test_shutil
0:00:00 load avg: 1.46 Run tests sequentially
0:00:00 load avg: 1.46 [1/1] test_shutil
test test_shutil failed -- Traceback (most recent call last):
File "/Users/e/Github/cpython/Lib/test/test_shutil.py", line 1592, in test_tarfile_vs_tar
self.assertEqual(self._tarinfo(tarball), self._tarinfo(tarball2))
AssertionError: Tuples differ: ('dist', 'dist/file1', 'dist/file2', 'dist/[31 chars]ub2') != ('._dist', 'dist', 'dist/._file1', 'dist/._[122 chars]ub2')
First differing element 0:
'dist'
'._dist'
Second tuple contains 6 additional elements.
First extra element 6:
'dist/file1'
- ('dist', 'dist/file1', 'dist/file2', 'dist/sub', 'dist/sub/file3', 'dist/sub2')
+ ('._dist',
+ 'dist',
+ 'dist/._file1',
+ 'dist/._file2',
+ 'dist/._sub',
+ 'dist/._sub2',
+ 'dist/file1',
+ 'dist/file2',
+ 'dist/sub',
+ 'dist/sub/._file3',
+ 'dist/sub/file3',
+ 'dist/sub2')
test_shutil failed (1 failure)
== Tests result: FAILURE ==
1 test failed:
test_shutil
Total duration: 871 ms