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"
I have a very annoying problem that I've been trying to fix all day. I'm working on a Flask API in Python 3.9.6; running in a venv. I have pip installed and imported flask-jwt-extended for authentication purposes, but neither VSCode nor Pycharm can find the module? The pipfile even says that version 4.1.0 is included in the dependencies. Originally it said 3.7.0 so I tried upgrading to 4.1, but no change. I tried removing JWT and PYJWT and reinstalling them, running flask-jwt-extended with and without them... just about every combination I can think of, but it just keeps throwing
ModuleNotFoundError: No module named 'flask_jwt_manager'
every. single. time. I've visited quite a few sites and some people seem to have run into the same situation and were able to resolve it through various means, but none have worked in my case. Does anyone have any idea on what is going on here? Here is my pipfile:
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
flask = "*"
flask-cors = "*"
bson = "*"
flask-pymongo = "*"
pymongo = {extras = ["srv"], version = "*"}
dnspython = "*"
flask-jwt-extended = "==4.3.1"
pyjwt = "*"
[dev-packages]
[requires]
python_version = "3.9"
and my imports at the top of my api:
import datetime
import json
import pymongo
from flask_jwt_extended import JWTManager
from bson.objectid import ObjectId
from flask import Flask, jsonify, make_response, Response, request
from flask_cors import CORS
from pymongo import ReturnDocument
from werkzeug.security import generate_password_hash, check_password_hash
From what I've read, flask-jwt-extended requires PyJWT, but I've tried it both with and without it installed; no luck. I'm a newbie, so forgive me if I'm missing something stupid. (On a 2019 MacBook Pro if that matters; people have told me the M1 chip has caused issues in the past)
So the good news is there's nothing wrong with the dependcies; if you have docker you can run the script below to prove it is working.
Therefore it must be environmental. Are you definitely using the right virtualenv? You must run your python through pipenv for it to pick up the right enviornment, or configure your IDE as such.
PROJECT_NAME=check-pipenv
PYTHON_VERSION=3.9.6
cd "$(mktemp -d)" || exit
cat << EOF > Pipfile
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
flask = "*"
flask-cors = "*"
bson = "*"
flask-pymongo = "*"
pymongo = {extras = ["srv"], version = "*"}
dnspython = "*"
flask-jwt-extended = "==4.3.1"
pyjwt = "*"
[dev-packages]
[requires]
python_version = "${PYTHON_VERSION}"
EOF
cat << 'EOF' > ${PROJECT_NAME}.py
import datetime
import json
import pymongo
from flask_jwt_extended import JWTManager
from bson.objectid import ObjectId
from flask import Flask, jsonify, make_response, Response, request
from flask_cors import CORS
from pymongo import ReturnDocument
from werkzeug.security import generate_password_hash, check_password_hash
print('Working')
EOF
cat << EOF > Dockerfile
FROM python:${PYTHON_VERSION}-slim-buster
WORKDIR /workdir
COPY Pipfile Pipfile
RUN pip install pipenv
RUN pipenv install && pipenv run pip freeze
COPY . .
CMD [ "pipenv", "run", "python", "${PROJECT_NAME}.py"]
EOF
DOCKER_BUILDKIT=0 docker build --tag ${PROJECT_NAME}:latest .
docker run --rm --name ${PROJECT_NAME} ${PROJECT_NAME}:latest
prints:
Working
Well, it turns out it was the import statement. PyJWT needs to be imported as “import jwt”. Further complicating the situation was the fact that flask-jwt-extended is not compatible with basic “jwt”. So uninstall jwt, install PyJWT, install flask-jwt-extended and be sure to import PyJWT as “import jwt”.
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.
I'm trying to use cryptography package in Python in virenv but VsCode error is " no module with this name : Crypt.py(script) and Pipfile are in the same directory
...my direcotry > pipenv install cryptography
....>
crypt.py
from cryptography.fernet import Fernet
key = Fernet.generate_key()
print(key)
error :
from cryptography.fernet import Fernet
ModuleNotFoundError: No module named 'cryptography'
pipfile:
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
cryptography = "*"
[requires]
python_version = "3.8"
Make sure you're running python within the virtual env you set up with Pipenv:
pipenv run python my_script.py
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.