I want to install this library: https://github.com/stefanfoulis/django-phonenumber-field
I have done like this:
(venv) michael#michael:~/PycharmProjects/client$ pip install django-phonenumber-field[phonenumbers]
Requirement already satisfied: django-phonenumber-field[phonenumbers] in ./venv/lib/python3.8/site-packages (5.1.0)
Requirement already satisfied: Django>=2.2 in ./venv/lib/python3.8/site-packages (from django-phonenumber-field[phonenumbers]) (3.2.3)
Collecting phonenumbers>=7.0.2; extra == "phonenumbers"
Downloading phonenumbers-8.12.23-py2.py3-none-any.whl (2.6 MB)
|████████████████████████████████| 2.6 MB 2.8 MB/s
Requirement already satisfied: sqlparse>=0.2.2 in ./venv/lib/python3.8/site-packages (from Django>=2.2->django-phonenumber-field[phonenumbers]) (0.4.1)
Requirement already satisfied: asgiref<4,>=3.3.2 in ./venv/lib/python3.8/site-packages (from Django>=2.2->django-phonenumber-field[phonenumbers]) (3.3.4)
Requirement already satisfied: pytz in ./venv/lib/python3.8/site-packages (from Django>=2.2->django-phonenumber-field[phonenumbers]) (2021.1)
Installing collected packages: phonenumbers
Successfully installed phonenumbers-8.12.23
We can see that this library has installed its dependency: phonenumbers library.
But now I want to write in requirements.txt that I need django-phonenumber-field of a certain release. So that its dependency should be installed as appropriate.
In other words how to write requirements.txt for future pip install -r requirements.txt.
Could you help me here?
=====ADDED LATER=======
pip freeze > requirements.txt doesn't seem to be appropriate as it will contain all the dependencies. It will become overburden with dependencies. I will forget why a particular library is installed. Whether it is a dependency at all. If it is, what library depends on it.
I want to keep requirements.txt as clear as possible.
In this particular example I want just one directive: install django-phonenumber-field==5.1.0 and manage dependencies yourself.
Wrong way (bloated and unclear what to delete if I stop using the library):
django-phonenumber-field==5.1.0
phonenumbers==8.12.23
What I want:
django-phonenumber-field==5.1.0 [and all dependencies]
As #jonrsharpe said, you can use pip freeze which lists all your dependencies, and redirect the output to your requirements.txt file to update it.
pip freeze > requirements.txt
The simple way is to create a text file, type the shell commands in, save it and the rename it from .txt to .bat. Now you can double click the file and it installs the requirements. You could probably even execute the .bat
Related
I have a Python tox project where I run the tox for running the test case and I came across one error a few hours back and am unable to resolve it till now. My module is using boto3 library and is installed using both the commands:
pip3 install boto3
pip install boto3 //for venv environments
When I try to install it again it gives me the below stack trace:
Requirement already satisfied: boto3 in ./venv/lib/python3.8/site-packages (1.26.34)
Requirement already satisfied: botocore<1.30.0,>=1.29.34 in ./venv/lib/python3.8/site-packages (from boto3) (1.29.34)
Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in ./venv/lib/python3.8/site-packages (from boto3) (1.0.1)
Requirement already satisfied: s3transfer<0.7.0,>=0.6.0 in ./venv/lib/python3.8/site-packages (from boto3) (0.6.0)
Requirement already satisfied: urllib3<1.27,>=1.25.4 in ./venv/lib/python3.8/site-packages (from botocore<1.30.0,>=1.29.34->boto3) (1.26.13)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in ./venv/lib/python3.8/site-packages (from botocore<1.30.0,>=1.29.34->boto3) (2.8.2)
Requirement already satisfied: six>=1.5 in ./venv/lib/python3.8/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.30.0,>=1.29.34->boto3) (1.16.0)
But when I run tox it gives me the below error:
File "/Users/tony/IdeaProjects/abc/provisioner/.tox/py38/lib/python3.8/site-packages/api/lambda_handler.py", line 1, in <module>
import boto3
ModuleNotFoundError: No module named 'boto3'
Is there some path issue? I am using Python 3.8.10. I tried uninstalling and installing the packages but nothing changed.
Any help is much appreciated.
tox creates an isolated environment for building and testing. So, when you install a package somewhere, here boto3 with pip/pip3, maybe system-wide, tox ignores that - and that is a good thing, otherwise it would be impossible to have a clean test environment.
You need to provide the necessary dependencies to tox.
tox automatically installs a package, ie. when there is a setup.py or a pyproject.toml. You could also provide your dependencies directly via the deps configuration key:
[testenv]
commands = ...
deps = boto3
There is another way. You could "break" the test isolation by using the tox-current-env plugin, see https://pypi.org/project/tox-current-env/
Disclaimer
I am on of the tox maintainers.
I need help understanding whats wrong here.
I will try to explain this as best I can, but Im a bit new to PythonAnywhere. I get this error:
Traceback (most recent call last):
File "/home/HelliottChip/mysite/app/__init__.py", line 6, in <module>
from flask_migrate import Migrate
ModuleNotFoundError: No module named 'flask_migrate'
When trying to run my main.py file. But i have them all installed as shown in this code:
17:14 ~/.local/bin $ pip install Flask-SQLAlchemy email_validator flask-mail pyjwt flask-bootstrap flask-moment
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2
.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in links: /usr/share/pip-wheels
Requirement already satisfied: Flask-SQLAlchemy in /usr/local/lib/python2.7/dist-packages (2.4.1)
Requirement already satisfied: email_validator in /home/HelliottChip/.local/lib/python2.7/site-packages (1.1.2)
Requirement already satisfied: flask-mail in /usr/local/lib/python2.7/dist-packages (0.9.1)
Requirement already satisfied: pyjwt in /usr/local/lib/python2.7/dist-packages (1.7.1)
Requirement already satisfied: flask-bootstrap in /usr/local/lib/python2.7/dist-packages (3.3.7.1)
Requirement already satisfied: flask-moment in /home/HelliottChip/.local/lib/python2.7/site-packages (0.11.0)
Requirement already satisfied: Flask>=0.10 in /usr/local/lib/python2.7/dist-packages (from Flask-SQLAlchemy) (1.1.1)
Requirement already satisfied: SQLAlchemy>=0.8.0 in /usr/local/lib/python2.7/dist-packages (from Flask-SQLAlchemy) (1.3.10)
Requirement already satisfied: idna>=2.0.0 in /usr/local/lib/python2.7/dist-packages (from email_validator) (2.8)
Requirement already satisfied: dnspython>=1.15.0 in /home/HelliottChip/.local/lib/python2.7/site-packages (from email_validator) (1.16.0)
Requirement already satisfied: blinker in /usr/local/lib/python2.7/dist-packages (from flask-mail) (1.4)
Requirement already satisfied: dominate in /usr/local/lib/python2.7/dist-packages (from flask-bootstrap) (2.4.0)
Requirement already satisfied: visitor in /usr/local/lib/python2.7/dist-packages (from flask-bootstrap) (0.1.3)
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python2.7/dist-packages (from Flask>=0.10->Flask-SQLAlchemy) (1.1.0)
Requirement already satisfied: Jinja2>=2.10.1 in /usr/local/lib/python2.7/dist-packages (from Flask>=0.10->Flask-SQLAlchemy) (2.10.3)
Requirement already satisfied: click>=5.1 in /usr/local/lib/python2.7/dist-packages (from Flask>=0.10->Flask-SQLAlchemy) (7.0)
Requirement already satisfied: Werkzeug>=0.15 in /usr/local/lib/python2.7/dist-packages (from Flask>=0.10->Flask-SQLAlchemy) (0.16.0)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib/python2.7/dist-packages (from Jinja2>=2.10.1->Flask>=0.10->Flask-SQLAlchemy) (0.23)
I have gone down about every website I can find on how to fix this, but I'm lost. This is for a Flask app I have worked on for a while on Replit.com and it worked fine until the transfer to PythonAnywhere. I have been trying to get this out for around two weeks now ^~^ but yet still no luck to my avail. I used a lot of this guide to help me with it, as I am also practicing my web deployment skills. (Don't need judgment on the fact I'm using flask -3-) But could anyone take thier time to help me with this? If you can, thanks a lot.
Check if your web app on PythonAnywhere is set up to be run by Python 2.7 -- I see you're using pip install outside of a virtual environment which by default will use pip for Python 2.7 as you can see in the output (btw. it won't work on PythonAnywhere, you need to provide --user option). If you want to install packages outside of virtual environment for different version of Python, use pipX.X install --user ... (where X.X should be replaced by required Python version). Also, remember to reload the web app every time the setup is changed. And if you're really stuck, maybe try contacting PythonAnywhere support (support#pythonanywhere.com) or use their forums?
Hello #TutorialWarrior9776 my suggestion is:
Step 1:
Install virtualenv,
pip install virtualenv
Step 2:
Create env
virtualenv -p python3.8 NAME_ENV
Step 3:
Activate env and Install requirements.txt (file generated local machine contains module flask_migrate)
source NAME_ENV/bin/active
pip install -r requirements.txt
Step 4:
Set your env path in the section (web) of pythonanywhere, that's all;
https://help.pythonanywhere.com/pages/Virtualenvs/
(Section: Step 3: Configure your app to use this virtualenv)
Hope this helps ;)
I am trying to run a python-script on an aws ec2-instance using jenkins.
I get the following error:
[ProdTest] $ /bin/sh -xe /tmp/jenkins14047325752732522807.sh
+ python3 prod.py
Traceback (most recent call last):
File "prod.py", line 2, in <module>
import base
File "/home/jenkins-slave-strat/workspace/ProdTest/base.py", line 3, in <module>
import boto3
ModuleNotFoundError: No module named 'boto3'
Build step 'Execute shell' marked build as failure
Finished: FAILURE
on the ec2 instance:
$ python3 --version
Python 3.7.9
$ pip3 install boto3 --user
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Requirement already satisfied: boto3 in /usr/local/lib/python3.7/site-packages (1.16.25)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in /usr/local/lib/python3.7/site-packages (from boto3) (0.10.0)
Requirement already satisfied: s3transfer<0.4.0,>=0.3.0 in /usr/local/lib/python3.7/site-packages (from boto3) (0.3.3)
Requirement already satisfied: botocore<1.20.0,>=1.19.25 in /usr/local/lib/python3.7/site-packages (from boto3) (1.19.25)
Requirement already satisfied: urllib3<1.27,>=1.25.4; python_version != "3.4" in /usr/local/lib/python3.7/site-packages (from botocore<1.20.0,>=1.19.25->boto3) (1.26.2)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /usr/local/lib/python3.7/site-packages (from botocore<1.20.0,>=1.19.25->boto3) (2.8.1)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.20.0,>=1.19.25->boto3) (1.15.0)
How do i get python to access the packages in /usr/local/lib/python3.7/site-packages ?
Thanks to everyone taking the time!
Before I give a short answer, a few cautions:
I don't know what version of Linux (I assume) the EC2 instance is running.
As a result, it's unclear if Python 2 is installed, but since you used pip3 and not just pip, it seems like it might be.
You could try altering your $PATH variable, but it's generally considered a good practice to use virtual environments for Python. I'm personally a fan of Conda, but you can find guides for Pipenv as well. My advice is; install Conda via Miniconda, then do the following:
$ conda create --name myAppEnv python=your.python.version
$ conda activate myAppEnv
$ conda install [your libraries]
Andys-MacBook-Air:~ andyz.$ sudo pip install pandas
Password:
The directory '/Users/andyz./Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/andyz./Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pandas
Downloading https://files.pythonhosted.org/packages/86/ad/89670f4017b2459dfb5577775efbc4c6c20eb46728ac6e5b721602493724/pandas-0.23.4-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (15.0MB)
100% |████████████████████████████████| 15.0MB 1.2MB/s
Collecting numpy>=1.9.0 (from pandas)
Downloading https://files.pythonhosted.org/packages/c0/b9/2b485bb32d0b26631f433580d90daad5dea830e6dc5bd18c4f227b1829f7/numpy-1.15.4-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (24.5MB)
100% |████████████████████████████████| 24.5MB 932kB/s
Collecting python-dateutil>=2.5.0 (from pandas)
Downloading https://files.pythonhosted.org/packages/74/68/d87d9b36af36f44254a8d512cbfc48369103a3b9e474be9bdfe536abfc45/python_dateutil-2.7.5-py2.py3-none-any.whl (225kB)
100% |████████████████████████████████| 235kB 4.2MB/s
Requirement already satisfied: pytz>=2011k in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from pandas) (2013.7)
Collecting six>=1.5 (from python-dateutil>=2.5.0->pandas)
Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Installing collected packages: numpy, six, python-dateutil, pandas
Found existing installation: numpy 1.8.0rc1
Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
I'm trying to install python pandas through pip but for some ungodly reason when were I try to get pandas it always says that it is numpy and when I check to see if I have pandas in python it will say that panda is not in the existing directory. How would I uninstall numpy. so that I can get pandas
I am using python jira package installed using PIP in a virtual environment. Recently my script started to complain about jira package version:
$ ./my_script.sh
jira/client.py:282: UserWarning: You are running an outdated version of JIRA Python 1.0.3. Current version is 1.0.6.dev20160420173258. Do not file any bugs against older versions.
I tried upgrade using pip like:
$ pip install --upgrade --no-cache-dir jira
Collecting jira
Downloading jira-1.0.3-py2.py3-none-any.whl (46kB)
100% |████████████████████████████████| 51kB 175kB/s
Requirement already up-to-date: requests>=2.6.0 in <...>/.virtualenvs/jira/lib/python3.4/site-packages (from jira)
Requirement already up-to-date: requests-oauthlib>=0.3.3 in <...>/.virtualenvs/jira/lib/python3.4/site-packages (from jira)
Requirement already up-to-date: six>=1.9.0 in <...>/.virtualenvs/jira/lib/python3.4/site-packages (from jira)
Requirement already up-to-date: requests-toolbelt in <...>/.virtualenvs/jira/lib/python3.4/site-packages (from jira)
Requirement already up-to-date: tlslite>=0.4.4 in <...>/.virtualenvs/jira/lib/python3.4/site-packages (from jira)
Requirement already up-to-date: oauthlib>=0.6.2 in <...>/.virtualenvs/jira/lib/python3.4/site-packages (from requests-oauthlib>=0.3.3->jira)
Installing collected packages: jira
Successfully installed jira-1.0.3
I tried to remove installed jira package and install it freshly with same result. Pip always installs only version 1.0.3 but scripts complain about newer version.
My assumption is that 1.0.6 is marked as released (the check is inside the package itself) but not published (I don´t know if this is the right word) for pip to download.
Any clue?
Regards,
JrBenito
It appears there is a 1.0.6.dev20160420173258 version but this isn't being downloaded when using pip install jira. It can be installed by using the workaround found on the issue #156 for this new version. pip install https://pypi.python.org/packages/f6/ea/2535e412ff76d85da20d2be6d1eaf9aa5de49481da94f2fe7e8830eedd35/jira-1.0.6.dev20160420173258-py2.py3-none-any.whl Which it appears you have already commented on, so hopefully they resolve the issue permanently.
I had this same issue, even after specifically downloading the 1.0.6.dev20160420173258 version. When the client.py file gets the version information, it doesn't get the git changeset correctly and so returns 1.0.6 instead of 1.0.6.dev20160420173258.
For now I made a workaround by hardcoding the version number pulled from https://pypi.python.org/pypi/jira/json
In /usr/lib/python2.7/site-packages/jira/client.py:
released_version = "1.0.6" # data['info']['version']
This is admittedly not a fix but lets hope it gets fixed.
It worked for me only after changed it to
/usr/lib/python2.7/site-packages/jira/client.py:
with
released_version = "1.0.6" # data['info']['version']