I am really frustrated right now and have tried so many workarounds all to no avail. I want to do some analysis on a csv file and I learnt that I would need to import pandas.
So I installed python version 3.10.5 and ran this code in terminal:
pip3 install pandas
This successfully installed pandas on terminal in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages
I ran this code on my Atom IDE and VScode too:
import pandas as pd
This was the error:
[Running] python -u "/Users/augustine/Downloads/pythonscripts/tempCodeRunnerFile.python" Traceback (most recent call last): File "/Users/augustine/Downloads/pythonscripts/tempCodeRunnerFile.python", line 1, in <module>
import pandas as pd
ImportError: No module named pandas
I saw on reddit that only python 3.9 supports pandas for now. I uninstalled version 3.10 and installed 3.9, on VS code, I changed the python interpreter to 3.9 version but it's the same thing happening. Please what am I supposed to do?
It's good practice that every time you make a new project involving python, to change to that project's base directory and then run python -m venv venv to set up a stable python environment there, when you use it you run ./venv/Scripts/activate, and then all dependencies can be managed in a requirements.txt file. The added bonus is if u do that, vscode will see it and then auto-suggest whether you want that to be the default interpreter for your project code. If that doesnt happen, try the magic "ctrl + shift + p" and then start typing "python interpreter" -- an option will appear for you "Python: select interpreter" and then just use the one you've created in the venv (./venv/Scripts/python.exe).
I think this is related to the existence of multiple Python in your environment. Try to manually specify the python location in setting.json:
"python.defaultInterpreterPath": "C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python310\\python.exe",#your python path
Related
I am using visual studio code on windows, and I am trying to run a python code on jupyter-notebook. I have all packages installed and they work fine when it is a normal python file. But I need it to run as a notebook. Once I run the block, I immediately get the following error:
ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_5668\1439934476.py in <module>
1 import csv
----> 2 from pandas import read_csv
3 from matplotlib import pyplot as plt
4 import numpy as np
5 import os
ModuleNotFoundError: No module named 'pandas'
I made sure that requirements are already satsified for this module, and I already tried running this line in python file with no issues. Therefore, how can I solve this issue? How can I let Jupyter notebook compiler to see where these packages actually are?
The installation of pip is related to the python path specified in the environment variable. You need to select the correct interpreter in vscode.
Python is an interpreted language, and in order to run Python code and get Python IntelliSense, you must tell VS Code which interpreter to use.
From within VS Code, select a Python 3 interpreter by opening the Command Palette (Ctrl+Shift+P), start typing the Python: Select Interpreter command to search, then select the command. You can also use the Select Python Environment option on the Status Bar if available (it may already show a selected interpreter, too):
Read docs for more details.
First you need to install pandas by running the command in your console:
pip install pandas
If you don't have pip installed on your computer then install it, otherwise you won't be able to download pandas or other modules
PS: check that when you downloaded python you chose the add to PATH option
Hoping I could help
If you have a problem running jupyter notebook file make sure
You have installed jupyter notebook from anaconda from this site
Once you installed that, open anaconda navigator and click environment tab
Install python and pandas
Jupyter Notebook works like environment different from VSCode
You can also run Jupyter Notebook file on VSCode by installing Jupyter extension in VSCode
My guess is you don't installed it yet in anaconda navigator, that's what makes it error
So I am trying to install and import pynput in VSCode but its showing me an error every time I try to do it. I used VSCode's in-built terminal to install it using pip and typed the following :
pip install pynput but this error is shown : Fatal error in launcher: Unable to create process using '"c:\users\vicks\appdata\local\programs\python\python38-32\python.exe" "C:\Users\vicks\AppData\Local\Programs\Python\Python38-32\Scripts\pip.exe" install pynput': The system cannot find the file specified
After receiving the following error, I tried using CMD to install it but the same error is shown. I also tried using python pip install pynput and it shows Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases. even though I have python 3.9.7 and I have selected it as my interpreter in VSCode and I have IDLE(Python 64 bit) installed. How may I resolve the following error? Any help regarding the same is appreciated
Thanks in advance :)
There's no such thing as an in-built terminal in VS code. When you open a terminal in VS Code, it opens the default, which on Windows is usually equivalent to opening up CMD.
If you selected Python 3.9.7 as your default interpreter in VS Code, it does not mean that it will visible to your CMD / terminal. It just means that the VS Code IDE will refer to that instance of Python when launching the program from VS Code itself using the green button (or F5), and when scanning your code to point out missing packages, etc.
CMD will only automatically detect your Python if it's in your PATH environment variable. You should add the Python 3.9.7 base and Scripts path to this.
Also, it would be best if you could first uninstall conflicting versions (like your 3.8.x) of Python and remove them from PATH, assuming that this won't cause any problems for you. Perhaps keep a record all the installed packages in this old version of Python for future reference using pip freeze or pip list.
Check if c:\users\vicks\appdata\local\programs\python\python38-32\python.exe exists by typing cd c:\users\vicks\appdata\local\programs\python\python38-32
I have installed sqlalchemy in my pathon. Im running python 2.7.15
When I execute my test program it says;
ImportError: No module named sqlalchemy.util._collections
I have installed modules with my python version.
Flask-SQLAlchemy 2.3.2
SQLAlchemy 1.2.2
WHy do I get this error in pycharm. PyCharm run configurations picks correct python version.
In console i tried the import statement it works.
$ python --version
Python 2.7.15
>>> from sqlalchemy.util import _collections
>>>
Why I get this error in pycharm?
First thing I would check is that you're using the correct Python environment in PyCharm.
Use the which python function in your console to see the path to the python executing in your terminal and make sure that it lines up with the path under "External Libraries" in your project view. You may not have sqlalchemy installed on the Python executable in your Pycharm Project. I've had similar issues in the past where I had Python installed alongside Anaconda.
Also consider dropping a requirements.txt file into the root level of your project in Pycharm. If your Python environment doesn't have the library installed it will generally prompt you to install it. Just add in a single line into your requirements.txt file with sqlalchemy. Using echo you could create this file using the following command
echo "sqlalchemy" >> requirements.txt
This is due to Pywren [1] library which could not import some 3 rd party libraries. Not a Python/PyCharm issue
[1]https://github.com/pywren
[2]https://github.com/pywren/pywren/issues/253
I have followed instructions out lined here:
http://forums.nuand.com/forums/viewtopic.php?f=9&t=2804
and installed GNU Radio from GIT repo (scroll down to the section that says "Building GNURADIO from GIT". I used the ./build-gnuradio.sh script to do this and it took a while, but it appeared to build successfully, as per the instructions.
I am running on Ubuntu 12.04 LTS.
When I attempt to run the "./uhd_fft" function I get the following error message:
Traceback (most recent call last):
File "./uhd_fft", line 23, in <module>
from gnuradio import gr, gru
ImportError: No module named gnuradio
I have Googled this error message and most of the forums claim there is a problem with the PYTHONPATH.
When I do
echo $PYTHONPATH
/usr/bin/python2.7
But when I check the python2.7 directory I do not see gnuradio. So I guess it makes sense I'm getting an import error when it tries to import gnuradio. But the bigger question is why?
I installed GNU Radio (per instructions from nuand forum) using ./build-gnuradio.sh script. So I should have it installed.
I would appreciate if it python / GNU Radio experts from the community could weigh in.
There is a section later in the instructions with this boldface label:
Now for some voodoo to get the new program installed into system libraries and python paths and executable path.
Those instructions lead you through modifying your PYTHONPATH to pick up the gnuradio module, among other things. If you have followed those instructions, you will have to start a new shell to see any effect, or execute the .sh file by hand, since profile scripts only run when a new shell starts up or when they're run manually.
One of the reason for this error is, when the default python is selected incorrectly. To see which python is selected type the following command in the Terminal:
"sudo port select python"
it will display all the python available on your mac.
like:
python26
python27-apple(Active)
python27
For Gnuradio you need python27,if other python is active like in the example above you can change it by the following command:
"sudo port select python python27"
Now RUN your python code,it should work.If python27 is already active you may consider changing the path manually as suggested by others
Try this once the PATH variables have been set.
ln -sf /usr/lib/x86_64-linux-gnu/libvolk.so.1.3.1 /usr/lib/x86_64-linux-gnu/libvolk.so.1.3
On OSX 10.12.3 (16D32) this worked for me:
export PATH=/opt/local/bin:$PATH
python
> import gnuradio
For me python at the prompt was using Mac's python instead of the one in
/opt/local/bin/python
The link you have provided also mentioned that you might need to add dist-packages and site-packages.
The following command solved the issue for me:
export export PYTHONPATH=/usr/local/lib/python3/dist-packages:/usr/local/lib/python3.6/dist-packages:\
/usr/local/lib/python3/site-packages:/usr/local/lib/python3.6/site-packages:$PYTHONPATH
I'm pretty new to python and twisted and I tried to run a simple twisted script but failed.
My environment:
MacOX 10.7.2 + Python 2.7.1 + Twisted 11.0.0 + eclipse + PyDev
The script called test.py:
from twisted import reactor
reactor.run()
I tried to run it in the terminal and everything works fine.
Then I opened eclipse and created a new PyDev project then adding a py file called test.py and
typed the code above in.
When I tried to run it I got errors like:
Traceback (most recent call last):
File "/Users/user/Documents/workspace/TwistedDemo/test.py", line 2, in <module>
from twisted import reactor
ImportError: No module named twisted
Then I checked the PYTHONPATH and added the "twisted source folder" in the external libraries tab but the errors was still there.(nothing changed)
Hope someone can help me out here, thanks in advance :)
Several things to try here -
Since your env is Mac OSX. I installed commandline tools from Xcode which solved this problem. Xcode 4.4 and later install Command Line Tools
For the sake of completeness. If this on Ubuntu, then apt-get install python-twisted generally works.
from your eclipse put this in your python script -
python -c 'import sys;print sys.path'
This tells all the paths that python looks for when you import something. If you don't find twisted path there then add it to this like so - sys.path.append(twisted_dir_path)
Finally, if all the above does not help. type -p python in a shell will tell you which version you're using; I would mostly be /usr/bin/ or some variant of it.
Then /usr/bin/python2.7 -c 'from twisted.internet.protocol import Factory,Protocol' ought to succeed.
This has happened to me so many times, but I figured out previously. Basically, if you have too many versions of python on your mac, Aptana Studio for some reason gets confused, so make sure that your twisted installation is using the same python as the command line (even though you already added twisted to Aptana). I'll get into more specifics later
Ok, I think this is how you do it:
Grab the python path of the python that has twisted installed correctly, using this
import sys
print sys.path
And just grab the base path, nothing to specific.
Go to Aptana-preferences-PyDev-Interpreter-Python
And then just add a new interpreter (in my case I just called it python1 and set is the first one. If that doesn't work then just set a new PYTHONPATH right below it.
You need to install incremental before twisted
pip install --upgrade incremental
pip install Twisted
This should solve the problem.
Not sure how you installed twisted, did you try easy_install or pip, or install in manually?
If you want to make sure it's installed properly, try opening up a terminal, typing python, and then "import twisted". If it comes back without errors, then it's installed. You might need to set the PYTHONPATH variable to include the source folder.
Then, since you're using pydev in eclipse, you need to refresh your configuration each time you add a new library.
On the mac, this is under preferences -> PyDev -> Interperter-Python
I find it works best to remove my configuration and re-add it, for it to pick up everything. But you can click on new folder (select the folder with the init.py), or the new egg, if it's an easy_install egg (a .egg file is a zip file, if it's unzipped, you'll see a EGG-INFO folder in the subdirectory of the folder you want to select).
You should set the correct PYTHONPATH in Eclipse as following:
right click your project.
select Properties
select pyDev-PYTHONPATH
add your twised in the external libraries