Question about 2 instances of package in pipfile - python

Im going through exercises on https://www.practicepython.org/
In ex17 there is a task to install packages "request" and "BeautifulSoup"
I did it but since an error occured i installed "BeautifulSoup" and "BeautifulSoup4"
Pipfile:
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
requests = "*"
beautifullsoup = "*"
beautifulsoup4 = "*"
[requires]
python_version = "3.7"
Will it couse any problems if i will import only beautifulsoup4?
Can I delete the beautifullsoup = "*" from file and it will be ok?
How can i do it?
Should i write additional commands in console?

Just run pipenv uninstall beautifullsoup to remove the installed package and you should be fine.

Related

How to install Python packes listed in `Pipfile` using `pipenv` and the `--target` flag (via `--extra-pip-args`)?

A) The following does not install the packages from Pipfile into the --target directory foo:
pipenv install --extra-pip-args="--target=foo"
B) On the other hand, this does install the explicitly specified package(s) (request in this case) into the --target directory foo:
pipenv install --extra-pip-args="--target=foo" requests
How can I make the first command work? It would be preferable, as Pipfile already has version-pinned packages listed:
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
requests = "2.28.2"
[dev-packages]
[requires]
python_version = "3.9"

Docker not recognising psycopg2-binary as psycopg2

Using pipenv I have the following pipfile:
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
flask = "*"
uuid = "*"
gunicorn = "*"
psycopg2-binary = "*"
[dev-packages]
[requires]
python_version = "3.8"
And then my Dockerfile is set up as follows:
FROM python:3.8.3-slim-buster
RUN useradd deploy_trial
WORKDIR /home/deploy_trial
RUN pip install pipenv
COPY . /home/deploy_trial/
RUN pipenv install --deploy
CMD ["python","./app/text.py"]
However, although the build seems to go successfully, when I run the image I get an error message saying:
Traceback (most recent call last):
File "./app/text.py", line 1, in <module>
import psycopg2
ModuleNotFoundError: No module named 'psycopg2'
So it obviously thinks that psycopg2 hasn't been installed... This is really strange because when I have used psycopg2-binary on my local machine and all of my programs there recognise the installation as psycopg2 when the code is run. Does anyone know how to fix this?
My dockerfile:
FROM python:3.8.3-slim-buster
RUN python -m pip install pipenv
COPY script.py script.py
COPY Pipfile Pipfile
RUN pipenv install
CMD ["pipenv", "run", "python", "script.py"]
script.py:
import psycopg2
print('it is ok')
Pipfile:
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
psycopg2-binary = "*"
[dev-packages]
[requires]
python_version = "3.8"
It works with such configuration.

ModuleNotFoundError: (already installed not working)

I can't figure out why Python will not recognize the modules. The packages are apparently installed in my pipenv according to my pipfile as you can see below.
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
requests = "*"
beautifulsoup4 = "*"
[dev-packages]
[requires]
python_version = "3.9"
yet, when I enter
import requests
from bs4 import BeautifulSoup as bs
in my .py file, I still get ModuleNotFoundError
Thank you for any help!
EDIT: found the pipenv command equivalent to pip freeze and this also shows I have requests installed. photo below

python pip: cannot install flask and zappa - contradicting requirements

I want to install flask and zappa, a common combination.
I use pipenv to create an evironment:
pipenv --python 3.6.4
I want to install packages:
pipenv install flask zappa
Unfortunately the requirements of flask is:
Werkzeug >= 0.14
the requirement of zappa is :
Werkzeug == 0.12
So this is not installable. What can i do?
Thanks to Evgeny this solution was successful. I could not find it in pipenv documentation.
Just manually edit the Pipfile:
Pipfile
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"
[dev-packages]
[packages]
zappa = { git = 'https://github.com/Miserlou/Zappa.git', ref = 'master', editable = true }
flask = "*"
[requires]
python_version = "3.6"

How to install python packages from more than pypi repository?

I'm using pipenv as package management tool and for my project I use packages from pypi and other private local project for that we did a private pypi repo, but when trying to install the packages, I got the following error:
File "/usr/local/Cellar/pipenv/8.3.2_1/libexec/lib/python3.6/site-packages/pipenv/utils.py", line 382, in prepare_pip_source_args
pip_args.extend(['-i', sources[0]['url']])
TypeError: 'NoneType' object is not subscriptable
My Pipfile looks as follow:
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"
[[source]]
url = "https://my.domain.com/repository/"
verify_ssl = true
name = "local"
[packages]
flask = "*"
sqlalchemy = "*"
gunicorn = "*"
...
my_project = {version="*", index="local"}
[dev-packages]
tox = "*"
pytest = "*"
"flake8" = "*"
[requires]
python_version = "3.6"
What I am doing wrong? How can I fix the issue!?

Categories