I am using VS Code using Python 3.9.1.
I have setup a venv called env. Folder structure is:
env
- Include
- Lib
- requests
- Scripts
- pyvenv.cfg
- scrape.py
In my script, scrape.py I have:
import requests
URL = "https://etherscan.io/token/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d"
page = requests.get(URL)
print(page.text)
I get the following error:
Import "requests" could not be resolved from source Pylance(reportMIssingModuleSource)
I have installed requests as you can see from the directory structure. A pip list gives the following which also shows requests is installed:
Use the command select python interpreter, setting it to your venv.
Make sure you Activate your venv in the console.
I think it'll add the string (venv) to your prompt. After running activate, pip and python now
There's additional guides here:
https://code.visualstudio.com/docs/python/environments#_where-the-extension-looks-for-environments
Related
I have the following uwsgi config:
[uwsgi]
callable=app
mount = /labs=/home/vinzee/projectname/app/wsgi.py
manage-script-name = true
touch-reload=/home/vinzee/projectname/app/wsgi.py
socket=/tmp/labshome.sock
processes=5
threads=1
venv=/home/vinzee/.virtualenvs/projectnamevenv38
chdir=/home/vinzee/projectname/app/
plugin=logfile,python3
logger=delete file:/dev/null/c.log
log-route = delete (\] POST \/save => generated )
pythonpath=/home/vinzee/projectname/
The virtual environment specified in venv uses Python3.8. And when reloading uwsgi, I get the classic error:
ModuleNotFoundError: No module named 'flask'
The same error happens when uwsgi's plugin is python and the project uses Python >= 3, as can be seen in this answer.
When I switch to Python3.6, the ModuleNotFoundError disappears and everything works properly.
I already have the package uwsgi-plugin-python3 to the latest version.
How can I get rid of this error for Python3.8? What package do I need to install?
It seems that this is a problem of creating a virtual environment.
virtualenv flask
cd flask
source bin/activate (for activate env )
also you can try to add your python path in wsgi file config
sys.path.append('/home/deployer/anaconda3/lib/python3.5/site-packages')
or
export PYTHONPATH=/root/environments/my_env/lib/python3.6/site-packages/
finally.. run :
python -m flask run
Before I explain my problem I want to start by saying that I have looked all over this site for an answer and tried almost all of them, to no avail.
I am on a windows machine, in a virtual environment. I have a command prompt opened in the virtual environment. I have already pip installed over a dozen modules that are being imported into my script and working perfectly. When I run the line:
from bs4 import BeautifulSoup
I get this error:
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
In my command prompt I can do 'pip list' and see beautifulsoup4 version 4.9.0. As well as in my virtual environment folder I can go into Lib\site-packages and I see all of my other installed packages that work in my script, along with a folder called 'bs4' and one called 'beautifulsoup4-4.9.0.dist-info'. I have also tried pip uninstall beautifulsoup4 and then re installed it, confirming that it did not show up in pip list between running those.
I am completely at a loss for why I cannot access the bs4 module. Anyone have any ideas for me to try? Thanks in advance.
EDIT: I am currently using VS Code and have pip installed several other modules including pymysql and google-api packages. I have successfully connected to my gmail and Amazon RDS database, so i know the other modules are working properly. For some reason its only BeautifulSoup4 I am having issues with.
EDIT 2: I opened up ipython from my virtual environment, and I entered from bs4 import beautifulsoup and i get this error.
ImportError: cannot import name 'beautifulsoup' from 'bs4' (C:\Users\Brian\Desktop\Projects\VirtualENVs\test_venv\Lib\site-packages\bs4\__init__.py)
EDIT 3: I finally just opened a new command prompt and pip installed beautifulsoup4 onto my computer outside of the virtual environment and now it works fine.
I am using Python38.
I am trying to create a script to create/modify google sheets. So I came across several articles detailing how to accomplish this: article1, article2, article3.
Essentially it boils down to using two python packages: GSPREAD and OAUTH2CLIENT.
The problem is trying to import either of these returns the Module Not Found Error.
Running this:
import sys
print(sys.path)
I see the site-packages directory is returned in the list.
I have many other packages installed in the same directory that do work (e.g. bs4, Django, Flask, matplotlib, etc, etc), so why are these two packages not being found? Does the PATH variable need to be updated?
Thanks in advance!!
So I failed to mention in the question that I was trying to do the pip install from the command line (cmd on windows). Which successfully installed the packages, but did not allow visibility to the rest of the python environments.
The way to get this to work was to run the pip install command from the Anaconda Prompt (Anaconda's command line).
I'm new to python so please be patient if i ask a silly question.
I am trying to use flask wtf class as seen in a tutorial.
My first line of the program is
from flask_wtf import FlaskForm
It gives me the error ModuleNotFoundError: No module named 'flask_wtf'
I have followed the following steps to make sure i have activated the virtual environment and flask wtf was installed in the virtual environment and not global.
Step 1: Went to the virtual environment and activated the environment C:\Users\Shraddha\PycharmProjects\FlaskProject\venv\scripts activate
Step 2: Installed flask wtf
C:\Users\Shraddha\PycharmProjects\FlaskProject\venv\scripts pip install flask-wtf
I see that flask-wtf is installed correctly in the folder C:\Users\Shraddha\PycharmProjects\FlaskProject\venv\Lib\site-packages
However when i try to run it using command prompt it does not give me anything and when i try to run it using sublime text it gives me ModuleNotFoundError: No module named 'flask_wtf' error.
I know this is a flask_wtf import error because other programs are executing as expected. Any help ?
If you start your virtual environment in the same dir as the file you are running doesn't that give access to the libraries in the install (ie everything shown in 'pip freeze' for the env)?
I faced same issue and tried all the approaches given on stackoverflow ImportError: No module named flask_wtf but didn't work for me.
I am using ubuntu 20.04 LTS operating system.
Note: To follow the given step you must activate your virtual environment.
I used:
pip3 freeze
which listed following directories
libries in my virtual environment
Then i tried the below command in the same directory
git clone git://github.com/lepture/flask-wtf.git
cd flask-wtf/
python3 setup.py install
Through the above commands i successfully installed flask_wtf as show below
installed flask_wtf
but then i faced the below error as i used email_validator in my forms.py file:
Exception: Install 'email_validator' for email validation support
Then I installed email_validator using following command
pip3 install email_validator
Then i successfully run my flask application. I am sure it will work for you too.
hello I'm new to python3 and python3.6, I usually use pip3 install to add old libraries to my python3 path.
I recently picked up python3.6 for managing my home servers with its asyncio functionalities however my python3.6 interpreter is unable to locate pwnlibs and am thus unable to reuse my old code.
I tried:
import sys
import os
sys.path.append(os.path.abspath(pwn.__file__))
import pwn
debugging results:
on python3.4 os.path.abspath(pwn.__file__) returns the correct path to the library
While sys.path.append is a valid means to add to your python path at runtime, you can't get the path from a module you have not yet loaded.
Instead you should install your packages using pip3 or in a specific location and add that to your path either at runtime or via the PYTHONPATH environment variable.
I would guess since you mentioned pip3 already however that you had the pwn package already installed when you tried with 3.4 and your install of Python 3.6 is not using the same paths as your Python 3.4 install. Try comparing your python paths from 3.4 with 3.6 by comparing the output from sys.path.
Lastly, just as a note, if you are using the pwntools package, it doesn't yet support Python 3, so if you are simply copying the folder, be aware it might not function correctly or at all.