let me explain the problem:
I have pyCharm, SublimeText, CodeRunner, and IPython Notebook. I've been exploring each one to see which i like best. Turns out to be PyCharm.
Here's the problem - CodeRunner recognizes the package for "Selenium", and gladly imports the module.
However, when I use pyCharm and iPython notebook, an import error occurs - which befuddles me. Why would it work for one IDE and not the another?
Also - i used "sudo pip install selenium" in the terminal. What exactly is the root of the problem? I feel like it has something to do with permissions, but am not knowledgeable of how to modify permissions for python packages.
Thanks.
In Pycharm you need to source the directory that contains the package Selenium.
In your project browser right-click a directory and select Mark directory as > source
eg:
/path/to/py/packages/Selenium/
You need to source the "packages" directory.
Related
im very new to code in general so this could be a stupid beginner problem ive searched for things but i couldnt find something useful for me
under Problems is the message: Import "pygame" could not be resolved
You can use pip show pygame to view the package installed location.
And check whether the installation location is consistent with the version corresponding to the selected Python interpreter.
There are two ways to solve this problem:
"ctrl+shift+P" and change the python interpreter.
If you don't want to change the interpreter, you can use pip -t flodername pygame #flodername is your used python package location. Install the pygame package to the specified directory
First, try restarting your computer or vs code
Use this command in your vs code terminal if the above doesn't work:
pip uninstall pygame
Then reinstall pygame using:
pip install pygame
If this also does not work then follow these steps:
Go to the scripts folder of python.
Open command prompt or Powershell in the script folder.
Use this:
C:\python34\scripts> python -m pip install pygame
Done
As an Anaconda user, I found my packages were being installed to C:\Users\YOUR_USERNAME\anaconda3\Lib\site-packages, which Visual Studio Code was not picking up on.
With the Pylance extension installed, open Settings (File > Preferences > Settings, or Ctrl+,)
At the top, beside Workspace, choose User
Under Extensions > Pylance, scroll until you find Python › Analysis: Extra Paths and select Add item.
Type in the path to which packages are being stored (in this case, C:\Users\YOUR_USERNAME\anaconda3\Lib\site-packages)
Click OK and after a couple moments, you should see something like the below image (i.e, the path is included in the list of paths).
Finally, your Python file should have picked up on the changes, but if not, reload it or VS Code. If nothing else, add another path that packages are being saved to or change your Python Interpreter. Using another virtual environment's interpreter wouldn't be very helpful, after all.
I may be late, but I hope this helped.
Error is: Import "brownie" could not be resolvedPylance
I know there are other SO posts that refer to this, but it seems most of them are talking about booting up a new env and installing x package into that virtual env.
However with Brownie, I'm especially confused because the brownie docs say:
pipx installs Brownie into a virtual environment and makes it available directly from the commandline. Once installed, you will never have to activate a virtual environment prior to using Brownie.
I don't want to mess with the virtual env that brownie uses.
Anyways, my code runs fine and the command line tells me that brownie is installed.It's just that this warning is really annoying me. Can anyone tell me how to clear it up? Thanks!
open command pallete cmd+shift+P (on mac)
type python select
click Python: Select Interpreter
Enter interpreter path
~/.local/pipx/venvs/eth-brownie/bin/python
this works for me.
It's happening because we install python with pipx instead of pip. pylance looks in the location our pip files are generally stored, and doesn't see brownie since we installed with pipx (which installed to it's on isolated virtual environment). So you have a few options:
Ignore it
Install brownie with pip in a virtual environment (not recommended)
If there is another suggestion, happy to hear it
for Windows:
Ctrl+Shift+P
Type python select
click Python: Select Interpreter
Enter interpreter path ~/.local/pipx/venvs/eth-brownie/Scripts/python
You can also click "Find" to search your files for the path if manually inputting it isn't working
This is an addition to #Ali Sıtkı Aslantaş's answer
I tried below pip command & the warning in my python code got resolved.
pip install brownie
The answer is probably quiet simple, as for me, each time I have to use different packages, I need to select the right interpreter in order not to get that silly warning.
If you are on Windows (I assume you are using VS code) follow the following steps:
View > Command Palette
Search for "Python: Select Interpreter"
Select "Enter interpreter path..." > "Find..."
Enter this path "C:\Users<< username >>.local\pipx\venvs\eth-brownie\Scripts" (of course swap << username >> with your username)
Select as interpreter the "python.exe" file contained inside of the Scripts folder.
Otherwise, if you are on an Apple device, the Steps to follow should be pretty much the same but at point 4) you need to enter a path that looks similar to the following: ~/.local/pipx/venvs/eth-brownie/bin/python.
So far, this method allowed me to solve any "Import" could not be resolved in Pylance.
The suggested methods seem correct, however, all of them are for Linux/OS, making the answer really confusing for the windows users.
I followed Patrick's tutorial and my path is: C:\Users\korisnik.local\pipx\venvs\eth-brownie\Scripts
^Korisnik Being the name of the account. It's honestly hard to find path if you don't know where to look at.
When I am writing
from flask import Flask
One Yellow line is coming up under flask and stating Import "flask" could not be resolved from source Pylance (reportMissingModuleSource) . Also, I am able to do the work with this package also successfully. But the thing is, I am not able to use autosuggesstions for Classes and methods very well.
Further:
I have checked that flask is installed successfully.
Also I visited this thread https://github.com/microsoft/pylance-release/issues/236
And I set up my settings.json in vscode as follows:
"python.analysis.extraPaths": [
"/media/sarimurrab/New Volume/COURSES/Flask/FlaskMigrateforDatabaseMigrations/2"
]
But Still, unable to resolve the error.
When I did not install the module "flask" in the Python environment currently used in VSCode:
Please use the command "pip --version" to check the source of the module installation tool "pip", the module is installed at this location:
Then, we can use the command "pip show flask" to check the installation location of the module "flask": (It checks whether the installation location of the module is consistent with the Python environment displayed in the lower left corner of VSCode.)
If the "reportMissingModuleSource" message is still displayed here, please reload VS Code.
(F1, Developer: Reload Window)
Are you using a Virtualenv? If so make sure that VSCode is using the virtualenv as your python interpreter, otherwise it will not be able to pick up the packages that you installed inside this virtualenv.
To do so, click on the Python interpreter in your bottom bar, you should get a list of possible python interpreters including your virtualenv.
I had a similar issue while trying to import flask on vscode.
I fixed it by using anaconda. Simply you install the flask module in your created environment example screenshot.
How to create a virtual env in anaconda:
1. On the left sidebar, click on environments.
2. Click create (at the bottom).
3. At the pop-up window, give your vir.env a name
and select the language version.
4. Once created, you can start installing
different modules in your environment.
I hope that helps!
For Linux Mint and for those who have installed flask, but VSCode doesn't find it:
check the Flask path: pip show flask (should be smth like
Location: /home/<username>/.local/lib/python3.8/site-packages
in VSCode click left bottom button and choose the python interpreter, in my case I changed it from python3.9 to python3.8 as we can see it in the flask path.
That's because you have not chosen your path correctly,
type:
pipenv --venv
then it will show you where your virtual env is installed. Check where the packages are installed in your env, and then type what comes to you from the shell\scripts or whatever\python, and the packages will work.
I solved my problem by using a "Global" version of Python. Maybe Pylance had not updated to work with the version of Python I was using.
interpreter language screenshot
I was facing same issue. I tried all solutions from stack-overflow but none worked. But after lot of searching and time waste I found my silly mistake. I had created folder named 'flask' and stored my project there. I'm beginner and going through lot of such silly mistakes. Hope it would help, if somebody commits same mistake.
I think this is a Vscode problem ,just restart the Vscode .
By the following steps, I solved this issue:
1)On the project directory create the .flaskenv file
In the .flaskenv file write the following two lines:
FLASK_ENV=development
FLASK_APP=main.py
Please pay attention that main.py is my main file after writing flask run in the Vscode terminal, additionally, you have to create an env folder or requirement file proviosly.
A few answers (Jill's, Marius's, and Roy's) mention the fact that is necessary to choose the correct Python interpreter to make Pylance function properly. I would like to add the fact that this is still necessary to do when using a Jupyter Notebook with the correct Python kernel already chosen.
It is counterintuitive to choose both Python interpreter and notebook's Python kernel to make things work. It is even more counterintuitive considering the fact that Python interpreter's button (on the left bottom of the screen, on status bar) does not necessarily appear when a Jupyter Notebook is open, but when a Python script is open. For instance, in this screenshot, we see the little line under Scikit-learn's import, indicating a problem with the import (even though the import is successful). However, the correct Python kernel, with Scikit-learn installed, is already chosen. Only opening a Python script we notice that the Python interpreter is the reason of this behavior, because a wrong one is chosen, without Scikit-learn. In some sense, one could think that the reason behind this was a problem with the Python kernel or the Conda environment (it is common to experience this kind of problem when experimenting with Jupyter Notebook and Jupyter Lab). I hope this answer may help those who are searching for solving this problem in the specific context of Jupyter Notebooks inside VS Code. They could ignore the other answers because they could think it is not the case for them.
I am trying to setup Atom as a Python IDE.
I have installed atom-ide-ui, and ide-python packages. Python and pyls are installed as well to the latest versions. Nonetheless I am not able to use any of the functions the packages should provide (e.g. autocomplete, highlighting, etc.), they just do not seem to be active.
I have tried to set the python-ide Python Executable path to the actual install path (C:\Users\user\AppData\Local\Programs\Python\Python38-32\python), as I though it could be a problem with the defaults. Still nothing.
I am wondering if I am missing any import step in the setup, or if I am using something wrongly.
Thanks in advance.
Did you load the language-python extension? Its necessary to run Python. Was your file in color after opening a valid python code?
You should also load the extension named Script. Script is required to run your python file. after you start atom, under the Packages menu you'll see the word Script. Click on this and you'll get another pane that says run script. Click on this to run you python code/
Hi I'm really new on the programming. I am using VS Code with Anaconda interpreter:
Here
I am using Windows 10
I want to import "requests" module on my VS Code. I opened cmd and wrote "pip3 install requests" but it told me "Requirment already satisfied:" etc... Then I tried to download with Anaconda. I opened my cmd and wrote "conda install requests" and I downloaded.
Then I wrote this code to try module: Here
But I received an error in VS Code like that: Here
What can I do to solve this problem? Thank you so much for your answers. (By the way, sorry for my bad English :D I hope I explained my problem.)
Click in bottom left cornet in VS code on (Python <Version>) and then choose the python version that in your system.
I have just found the answer. In VS Code, I open powershell and write "py (filename).py". But just now, I tried to click top-right button which name is "Run Python File in Terminal" (green button). Then code executed successfully. I didn't take an error.
Check the following prospects in vscode with python extension:
When selecting interpreter, press ctrl+shift+' to open a new integrated terminal. If you selected base:conda environment, the terminal should be like this:
Then use pip list to show modules you've installed, if module requests not there, type commands pip install requestsin the terminal;
click then create a launch.json file, select Python File. This creates and opens a launch.json. You can close it or add configurations you want. More guidance about debug configurations you can reference: Python debug configurations in Visual Studio Code. Press F5 to run your code.
Just make sure the module installation is in the same environment as interpreter you've selected.