Problem with running python code on VS Code - python

[enter image description here][1]
Hello there,
I am facing the problem you can see in the image.
[1]: https://i.stack.imgur.com/qjV9Z.png
I have python installed in the D directory and added to path, everything looks like it should work.
I am creating a virtual environment for every project I am working on and I don't have any problems running commands like "pip install numpy" but when I try to run my code, even trying to import libraries it fails and the output in the picture is not very significant to me.
Has anyone faced a similar problem? can anyone help me?
Thanks in advance!

Judging from your screenshot, you have a file named numpy.py somewhere in your PYTHONPATH, causing Python to import that particular file instead of the NumPy library you intended.
See this link for more information on how Python import works: https://bic-berkeley.github.io/psych-214-fall-2016/sys_path.html

Related

Python "ImportError: cannot import name 'pnoise1' from 'noise'"

I have been trying to use the noise module in Python for a game I was making. I am on the Mac OS, and I used pip3 install noise to download the module. I uninstalled and reinstalled it multiple times, without the wheel library, and with, as it recommended. The noise module itself downloads fine, but every time I try to import pnoise from it, I get an ImportError.
Just straight up importing noise (import noise) gives me no error, it just prints a string of numbers to my console. Also, downloading and running the module in a virtual environment works, so it must be something on my computer or OS.
Code: from noise import pnoise1
Error: ImportError: cannot import name 'pnoise1' from 'noise'
I have looked for a while for a solution, but nothing has seemed to help, it just doesn't work. The only information I have found is that this may be a file problem, but I haven't found out how to fix it.
Any help would be greatly appreciated.
Edit:
I ended up figuring it out. I was importing a file by the same name instead of the library. Thanks for the help, everyone!
To me it works ok. Have you installed it correctly via pip/pip3?
Ended up figuring it out, I was importing a file of mine instead of the library. Thanks for the help!

how to import proper python module on virtual environment

I have this problem, that cannot import torch and torchvision well.
Currently, I am using the virtual environment, juneon, using Anaconda.
I think I set the library path and python path properly like the first following image.
Running the python file does not matter, However, during debugging, they cannot find those modules via VSCODE. I posted the second following image I've been seeing.
What should I check in order to solve the problem?
FYI, the third image is my file tree
Please let me know what I am missing!
Thank you in advance.

Installed pandas, but still get an import error when running code

I am using Ubuntu Linux server, and I am trying to use pandas, but I wrote code in a vim file, and when I try to run it, it says import error, no module pandas found. But if I open up an python3 environment, then it works. Any help will be appreciated, thank you!

Undefined variable from import when using vtk

I am coding in python 2.7 using python-vtk 6.2.0 installed with the Ubuntu package manager.
I use eclipse + pydev as IDE and I can run the code successfully in shell and from within eclipse.
The only annoying problem I have is that the code analyser keeps posting errors of the type: Undefined variable from import: vtkxxxxxx whenever I do
import vtk
vtk.vtkTransformPolyDataFilter
vtk.vtkActor
vtk.vtkWhatever
I tried to reset the interpreter and I have also tried to manually add the library .so files to the PYTHONPATH, with no luck.
Also I can see the the vtk package in the project tree under system libs and I have no errors on the line import vtk
Is there a particular unusual way to include vtk library in pydev? Am I doing something stupid I do not see?
Thank you all!
I have found a similar question already asked about numpy. It has been solved so maybe you might find your answer in there. The URL for the issue is https://stackoverflow.com/a/14082269/7171962
Btw. This may be of no help to you.
I hope this helps.
had you gone through this link enter link description here
Hope this will help

Splitting python code into different files (added picture of directory)

As my python code is getting longer, I would like to split it into a different files for better organization. In the same folder I created 2 files 'firstfile.py' and '2ndfile.py'
Below is the code of 'firstfile'
import pandas as pd
df=pd.DataFrame({'a':[2,4],'b':[2,1]})
Below is the code of '2ndfile'
import firstfile
print(firstfile.df)
Can I know why does the below error appear when i run '2ndfile'?
ImportError: No module named 'firstfile'
Hi, I tried the suggestions below including using dot something but it still does not work. Below is a screen shot of my directory. Is it related to some sys.path problem? I am currently using Spyder 2, python 3.5.
Try importing it with the from . import firstfile. Maybe you have Python3 which doesn't allow for implicit imports.
Switching from using Spyder2 python 3.5 to pyCharm solved the issue.

Categories

Resources