I am new to PyCharm (coming from RStudio world). I am just trying to setup a PyCharm project. My first line of code is google library import (Later I intend to write codes for pulling data from BigQuery).
But I am getting an error saying ModuleNotFoundError: No module named 'google' in PyCharm. I tried suggested solutions for a very similar stackoverflow question.
I also tried invalidating cache and restart by doing File >
I can see that the google is installed in the Python interpreter. I am not able to figure out what's the issue. To me looks like it is related to the way we setup environment in PyCharm.
Edit: I checked Project interpreter and Run Configuration interpreter. Both match and still get the same thing.
The library you want to use is not named google, is called google-cloud-bigquery, just install that one.
Look here:
https://cloud.google.com/python/docs/reference/bigquery/latest#windows
I guess you know, but you can install it with pip (like in the above link) or in Pycharm settings (clicking in the + in your third screenshot).
Related
I have a question regarding h5pyViewer to view h5 files. I tried pip install h5pyViewer but that didn't work. I checked on Google and it states that h5pyViewer does not work for older versions of Python, but that there are a few solutions on GitHub. I downloaded this with pip install git+https://github.com/Eothred/h5pyViewer.git which finally gave me a successful installation.
Yet, when I want to import the package with import h5pyViewer it gave me the following error: ModuleNotFoundError: No module named 'h5pyViewer'. However when I tried to install it again it says:
Requirement already satisfied: h5pyviewer in c:\users\celin\anaconda3\lib\site-packages (-v0.0.1.15)Note: you may need to restart the kernel to use updated packages.
Any ideas how to get out of this loop or in what other way I could access an .h5 file?
There could be so many things wrong so it's hard to say what the problem is.
The actual package import has a lowercase "v": h5pyviewer (as seen in your error message).
Your IDE/python runner may not be using your Conda environment (you can select the environment in VSCode, and if you are running a script in the terminal make sure your Conda env is enabled in that terminal)
The GitHub package might be exported from somewhere else. Try something like from Eothred import h5pyviewer.
Maybe h5pyviewer is not even supposed to be imported this way!
Overall, I don't suggest using this package, it seems like it's broken on Python 3 and not well maintained. The code in GitHub looks sketchy, and very few people use it. A good indicator is usually the number of people that star or use the package, which seems extremely low. Additionally, it doesn't even have a real readme file! It doesn't say how to use it at all. Suggest you try something else like pandas. But if you really want to go with this, you can try the above debugging steps.
So I want to run a repo i cloned from github project that is used to segregate the medical reports data and categorise it using machine learning and an error occurred.
Here is the relevant code:
import modeladapter as ModelAdapter
VSCode screenshot:
This means that the module does not exist on your PC in the area where Python modules are installed. You should try to install the module using pip and it should resolve I think. I don't know what the module is though, I tried googling it and couldn't find anything, so maybe somewhere on the GitHub repo page it says what the required modules are and where to get them?
So long story short. I want to use requests and bs4 modules in my code. I installed them using pip install requests, pip install bs4. I double checked everything, even found installation folder and saw that the files is here, but my vs code is not detecting it and giving a error. I'm a quite new to this programming language so possibly it's a common issue. But i searched and mostly found posts about this problems on diffrent versions of linux, not windows.
Error i'm getting in vscode btw
Import "requests" could not be resolved from source
And when i'm launching the program through cmd the error is
ModuleNotFoundError: No module named 'requests'
First, you should add more information for us to know how your computer and IDE are configured. The first thing you should do is to check that VS Code is using the Python version where you have pip installed the modules. That is, clicking at the bottom-left space as in the picture below. Then checking that the modules are within that path.
Otherwise, check out virtualenv. With this tool you can create virtual environments within your project's folder and makes it easier to manage packages.
X in this example represents any module or package you install.
The problem:
I have a problem with a package called 'X'.
In PyCharm I get an error ImportError: No module named 'X'.
My code runs from the terminal without any problem. Any help ?
or
I installed X on python3.4 with pip. In terminal, when I import X, everything is fine, but when I import it in PyCharm, it says: ImportError: No module named 'X'". Any help ?
This is basically everyday question, just with different module or a package instead name instead of X.
And it's not problem in a package or module you install, it's in a PyCharm Project Interpreter you are currently using for your project.
The following answer is usually solution to this specific problem.
SHORTER VERSION:
If you have squiggly line below module you import...
...move on name of module and press Alt+Enter and select Install package X.
This should (probably !!!) install module you thought you installed, but got ImportError.
LONGER:
If you want to use module X:
Go to File -> Settings -> Project:NameOfProject -> Project Interpreter.
The window that opens has some specific regions:
This is a project interpreter PyCharm is currently using. You can change you python environments here also. If you want to add virtual environment you created manually, continue reading.
A little "cog" or a "gear" is used to Add, Edit or Remove environments. If you want to add virtual environment you created manually, select Add... when gear icon is clicked, and make sure to set proper path to python.exeof your virtual environment.
IMPORTANT: A list of all installed packages, represented by: Package name and Version. If you tried to use package, but got ImportError no module named 'X', make sure to check if package is listed here!!!. If not, it's not installed in the current python environment and it should be installed (continue reading).
A little + represents Install. It can be used to install packages. Simply click on + sign, search for a package and click Install Package at the bottom after you found it. You can also specify the version you want of a package. In example below, we searched for flask package.
A package should be installed and listed now in installed packages.
PyCharm creates a virtual environment with its own Python Interpreter for your project, you need to install the module for the interpreter you are using. To do this go to Settings -> Project: yourProjectName -> Python Interpreter, click the plus icon and select the module you would like to install.
Alternatively you could force PyCharm to use your other Interpreter by selecting it from the dropdown at the top of the Python Interpreter settings page I mentioned before.
There are many reasons for this.
The reason and fix I'm going to put here is extremely rare, just decided to put it hoping at least a single person can get help from this answer.
The issue
PyCharm treats __init__.py as a non python file.
This happens when you forgot to use .py extension in your code's __init__.py files, and then you add the extension later. Then pycharm starts treating all __init__.py files (even external library files) as non python. How strange?
Detect if the issue is this
Scroll click on the library name (not the module name).
Or right click and goto Declaration or Usages
You will see the library's __init__.py as plain text.
If you see the code as plain text, that's the issue!
The Solution
Find the file location in pycharm navigation. If you are using virtual environment, the file fill be in venv/lib/site-packages/{library_name}.
Right click on __init__.py, click override file type. Select python.
You'll see the error is gone!
I'm trying to set up a roguelike Python project, but I can't seem to be able to import libtcod module into my project. This helloworld crashes, and the IDE keeps telling me that there is no module named libtcodpy.
import libtcodpy
def main():
print('Hello World!')
if __name__ == '__main__':
main()
What is the proper way to import modules into Python projects? I'm used to Java, so I was expecting something along the lines of Maven to manage the dependencies. There indeed seems to be something like that in PyCharm as well, this package manager for the venv, which from what I gather serves to isolate the project-specific stuff from the OS- or python-global stuff:
but libtcod simply isn't present in the rather exhaustive list of modules that appears after clicking on the "+" button, just some other module that has something to do with libtcod library (I guess?). Moreover, all the tutorials I found on setting libtcod up advise one to manually copy over files somewhere or run some command that I suppose does the importing somehow and other such solutions, all of which i tried and none of which worked. I don't want to pollute my project structure by using such hodgepodge ways of handling dependencies if I can at all avoid it.
Q: How do I get libtcod to work in my PyCharm project in the most clean and convention-abiding way possible?
Take a look at this github project called tcod: https://github.com/libtcod/python-tcod/blob/master/README.rst#installation
It's a python port of libtcod.
To install using pip, use the following command:
python -m pip install tcod
If you get the error "ImportError: DLL load failed: The specified module could not be found." when trying to import tcod/tdl then you may need the latest Microsoft Visual C runtime.
Blockquote