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
Related
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"
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 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
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.
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!?