Archive for the ‘Python’ Category
The – externally-managed-environment – in Python
To avoid this message which is to force you somehow to create a virtual environment in python:
$ pip install .
error: externally-managed-environment
× This environment is externally managed
??> To install Python packages system-wide, try 'pacman -S
python-xyz', where xyz is the package you are trying to
install.
If you wish to install a non-Arch-packaged Python package,
create a virtual environment using 'python -m venv path/to/venv'.
Then use path/to/venv/bin/python and path/to/venv/bin/pip.
If you wish to install a non-Arch packaged Python application,
it may be easiest to use 'pipx install xyz', which will manage a
virtual environment for you. Make sure you have python-pipx
installed via pacman.
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
Just remove this in Linux:
sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED
If you are using Homebrew just go to:
cd /home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.2_1/lib/python3.12
and remove the file EXTERNALLY-MANAGED as well.
If on the other side, prefer to create a virtual environment, this is the way, install this package:
python3-venv
In the environment you prefer to work with, use this command:
python3 -m venv .venv
You can check all the installed packaged here:
user@server# ls .venv/
bin include lib lib64 pyvenv.cfg
Then you have to activate the environment:
source .venv/bin/activate
Then it’s possible to use pip to install packages in that environment:
pip install -r requirements.txt
pip install openai
That’s it.
To deactivate the environment:
deactivate
Tweepy changes on Python
I was trying to use a parameter with the module tweepy, and I realised that the new version 4.0, has a change, well is very simple but it could create a whole new checking in your code, so it’s better to know already.
The change is, for ex. in the parameter ‘search’:
api = tweepy.API(auth)
for tweets in api.search(q="iphone", lang="en"):
print(tweet.text)
Now, Tweepy v4.0.0 was released and renamed API.search
to API.search_tweets
.
I would recommend simply renaming your method call, but you could also downgrade to Tweepy v3.10.0.
It’s not nice, in my opinion to be changing all the time little parameters, but now it would be something like this:
for tweets in api.search_tweets(q="iphone", lang="en"):
print(tweet.text)