(Python) psycopg2 installation - python

I have a fairly light amount of experience with Python and got stuck on what should be a pretty simple issue. I am using Jupyter Notebook on a Mac.
I wanted to install psycopg2 in Python so I typed in
import psycopg2 as pg2
But, I got the following error:
ModuleNotFoundError Traceback (most recent call
last)
<ipython-input-1-32fa0c891bdd> in <module>
----> 1 import psycopg2 as pg2
ModuleNotFoundError: No module named 'psycopg2'
I then went over to the terminal and typed in:
pip install psycopg2
which resulted in another error:
Error: pg_config executable not found.
pg_config is required to build psycopg2 from source. Please add the
directory
containing pg_config to the $PATH or specify the full executable path
with the
option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
I'm not sure how to go about using this information in the error message. Can someone help point me in the right direction?
Also follow up question:
a.) Why would I need to use pip install modulename in the terminal when I don't have to do that with either pandas or numpy?
Any help would be appreciated.

Please try installing psycopg2-binary as you probaly do not have all the C library dependencies installed on your computer.
pip install psycopg2-binary

Related

trying to fix no module named pkg resources error with poetry

im having an issue while trying to run autopytoexe lib. when searching for answers, i found this answer No module named pkg_resources and it was very helpful.
but im using poetry, and just run a poetry update setuptools didnt work well for me.
i tried to use pip install --upgrade setuptools in other project that i was having the same problem, it worked.
the error:
Traceback (most recent call last):
File "C:\...\.venv\lib\site-packages\eel\__init__.py", line 16, in <module> import pkg_resources as pkg
ModuleNotFoundError: No module named 'pkg_resources'
updating autopytoexe to grant that the problem isnt it:
PS C:\...> poetry update auto-py-to-exe
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 0 installs, 1 update, 0 removals
• Updating auto-py-to-exe (2.23.1 -> 2.29.0)
anyone has any idea why poetry cant help in this case? or dont work in this case..
yes im have to use windows at work pls dont judge

Can't install dbt-snowflake; "No module named 'cmake'"

(Context: Barely a novice at Terminal, know some SQL, don't know Python)
I'm taking a course on dbt, have my own Snowflake set up, and I'm trying to install dbt-snowflake on Mac. Attempting to run:
pip install dbt-snowflake
This fails, and it returns:
`
Traceback (most recent call last):
File "/Users/xxxx/course/venv/bin/cmake", line 5, in <module>
from cmake import cmake
ModuleNotFoundError: No module named 'cmake'
error: command '/Users/xxxx/course/venv/bin/cmake' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pyarrow
Failed to build pyarrow
ERROR: Could not build wheels for pyarrow, which is required to install pyproject.toml-based projects
`
I once successfully changed Python version in virtual environment to 3.9 to see whether that was the problem (but I can't replicate how I changed it), that didn't solve the problem, and currently it's back to 3.11.
Have installed multiple versions of snowflake (3.7, 3.9, 3.11). I don't really understand how this works in context of everything.
I have tried deleting and recreating virtual environments (under same name, venv)
uninstalled and reinstalled cmake (pip install --upgrade cmake); this is version 3.25.0
I don't understand how I can have cmake installed and be told there is no module named 'cmake'.
Is there a particular version of Python I should be running, and if so, how do I reliably change that in virtual environments and different directories?
EDIT TO ADDRESS A COMMENT: I installed Python versions via terminal brew install python#3.9

ModuleNotFoundError: No module named 'pyecharts'

I do not understand while running the example code from pyecharts, it is still giving me module not found error.
ModuleNotFoundError Traceback (most recent call last)
in
----> 1 from pyecharts.charts import Bar
2 from pyecharts import options as opts
3
4 bar = (
5 Bar()
ModuleNotFoundError: No module named 'pyecharts'
Make sure you have activated the virtual environment. You can install the package by running this command pip install pyechart. You should freeze the package into the requirements.txt file by running this command pip freeze -r requirements.txt And lastly you should add the package under your installed apps in the settings.py file, if any command exists for that. You could read the full documentation here https://pyecharts.readthedocs.io/en/latest/en-us/documentation/ to clear any further doubts.
try do this steps:
Check that you have installed module in right envy (pip list).
If you don't have, install by using pip (pip install pyecharts -U). see doc https://github.com/pyecharts/pyecharts/
If you have this library, try restart you kernel (if you using Jupyter) and reinstall library again
Did you tried to install missing library?
https://pypi.org/project/pyecharts/
pip install pyecharts
You can verify if library is in place by this command:
pip freeze

ModuleNotFoundError Despite being Installed

I'm having trouble loading a package that is installed in my environment and have no idea why..
conda list
fbprophet 0.3.post2 py36_0 conda-forge
When I request for libraries installed in conda, it clearly shows that I have fbprophet installed. Now, when I import it, a ModuleNotFoundError exception is thrown.
from fbprophet import Prophet
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-83be6864a7aa> in <module>()
----> 1 from fbprophet import Prophet
2 import numpy as np
3 import pandas as pd
ModuleNotFoundError: No module named 'fbprophet'
Has anybody run into this issue? What can I do to troubleshoot this?
My suggestion would be creating a virtual environment for your python first, then conda install your package in the virtual environment.
My script was reading from my pip install list where the module fbprophet did not exist. I went back and installed it there and everything worked. Lesson learned.
Always check where your libraries are being read from.
You may have more than one Python installation. Thus you might installed the library in one Python installation and tried to call it from another one. Please let me know if you have more than one Python installation by printing the result os this CMD command where python.

Setup script exited with error: Unable to find vcvarsall.bat

I got the folloiwng error while running my script
Traceback (most recent call last):
File "mysql.py", line 2, in <module>
import MySQLdb
ImportError: No module named MySQLdb
Tried to install mysql-python as suggested in No module named MySQLdb but running
into following error ,can anyone suggest how to overcome this error?
C:\Dropbox\scripts>easy_install mysql-python
Searching for mysql-python
Reading http://pypi.python.org/simple/mysql-python/
Best match: MySQL-python 1.2.5
Downloading https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c
Processing MySQL-python-1.2.5.zip
Running MySQL-python-1.2.5\setup.py -q bdist_egg --dist-dir c:\users\gnakkala\appdata\local\temp\easy_install-kowc5r\MySQL-python-1.2.5\egg-dist-tmp-1gslvq
error: Setup script exited with error: Unable to find vcvarsall.bat
I had a similar issue with getting MySQL-python to install properly and work for me. I tried both easy_install and pip, both had issues with vcvarsall.bat. Below is what I did to solve my problem, which I think might be able to lead you in the right direction. I have a Windows 8 Machine, Python 2.7 installed and running my stuff through eclipse.
Some Background:
When I did an easy install it tries to install MySQL-python 1.2.5 which failed with an error: Unable to find vcvarsall.bat. I did an easy_install of pip and tried the pip install which also failed with a similar error. They both reference vcvarsall.bat which is something to do with visual studio, since I don't have visual studio on my machine, it left me looking for a different solution, which I share below.
The Solution:
Reinstall python 2.7.8 from 2.7.8 from https://www.python.org/download this will add any missing registry settings, which is required by the next install.
Install 1.2.4 from http://pypi.python.org/pypi/MySQL-python/1.2.4
After I did both of those installs I was able to query my MySQL db through eclipse.
1 install wheel
pip install wheel
2 Download .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml
Ctrl+F, search mysql . you can find :
MySQL-python, a Python database API 2.0 interface for the MySQL database
Mysqlclient is a Python 3 compatible fork of MySQL-python.
MySQL_python-1.2.5-cp27-none-win32.whl
MySQL_python-1.2.5-cp27-none-win_amd64.whl
Mysqlclient, a fork of the MySQL-python interface for the MySQL database.
mysqlclient-1.3.8-cp27-cp27m-win32.whl
mysqlclient-1.3.8-cp27-cp27m-win_amd64.whl
mysqlclient-1.3.8-cp34-cp34m-win32.whl
mysqlclient-1.3.8-cp34-cp34m-win_amd64.whl
mysqlclient-1.3.8-cp35-cp35m-win32.whl
mysqlclient-1.3.8-cp35-cp35m-win_amd64.whl
mysqlclient-1.3.8-cp36-cp36m-win32.whl
mysqlclient-1.3.8-cp36-cp36m-win_amd64.whl

Categories

Resources