import module failed with running by console - python

First of all the project structure looks like this
-- ba-amin-code (main directory)
-- Diverse
-- LanguageIdentification.py
-- TextAlignment
-- FileHandler.py
-- TextHandler.py
I want to import a python file from TextAlignment when im in Diverse.
Project Structure, import statements
This is how I imported it, but im getting this error when running it like this
enter image description here
Is this way wrong to import?
Update:
This is how im importing two py files from TextAlignment.
Im in LanguageIdentification.py
import fasttext
import urllib
import typer
from TextAlignment import TextHandler
from TextAlignment import FileHandler
After that im running the program`from the root-directory (ba-amin-code) by console with this command
python Diverse/LanguageIdentification.py "INPUT.txt"
getting this error
Traceback (most recent call last):
File "C:\Users\Snur\Pycharm Projects\Gitlab\ba-amin-code\Diverse\LanguageIdentification.py", line 4, in <module>
from TextAlignment import TextHandler
ModuleNotFoundError: No module named 'TextAlignment'

The package might be installed in a different venv. Did you try running your code from the pycharm console, with your venv activated?
You have two yellow warnings in pycharm at your imports: what are they?
Otherwise, try the command: $pip list to see if the package is correctly installed in your venv.

Related

When trying to import selenium it does not work

When i attempt to import selenium i get the error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import selenium
ModuleNotFoundError: No module named 'selenium'
My selenium module is currently in:
C:\Users\Maseeek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\selenium
I've seen other people have it in a different directory and want to know how to fix it.
If you are using "PYCHARM" and if you created project with "Virtual Environment" you should choose "Python 3.x.x" instead of "Virtual Environment Python 3.9" that PyCharm created.
If you installed "anaconda" before you need to change paths of libaries.
If you're using PyCharm, then this might help:
PyCharm sometimes shows an error in importing modules that have already been installed (that's annoying). But, try to change the file location to this destination:
C:\Users\Maseeek\PyCharm Projects\(project name)\venv\site-packages\
or try installing the package in PyCharm using python with the following code:
from sys import *
from subprocess import *
call(["-m", "pip", "install", "selenium"])

I can`t import wxpython in anywhere except python console

I installed python 3.8.8 and installed wxpython using pip at terminal
pip install wxpython
and i run simple program
import wx
print(wx.version())
in pycharm and pycharm`s python console, I got
ModuleNotFoundError: No module named 'wx'
in IDLE, I got
Traceback (most recent call last):
File "C:/Users/tasoo/OneDrive/Desktop/wx.py", line 1, in <module>
import wx
File "C:/Users/tasoo/OneDrive/Desktop\wx.py", line 2, in <module>
print(wx.version())
AttributeError: partially initialized module 'wx' has no attribute 'version' (most likely due to a circular import)
in python.exe code works
I want to import wx in pycharm project.
I tried add python in system path but it didn`t work.
You have problem because you saved code in file wx.py and now import wx loads your file wx.py instead of module wx. Rename your file - ie. main.py instead of wx.py
PyCharm may have own Python installed and it may need to install wx in this Python.
Check
import sys
print(sys.executable)
to get full path to Python used by PyCharm and then use this path
/full/path/to/python -m pip install wx
Or search in PyCharm settings (in menu File) and change Python Interpreter.
In PyCharm for every project you may set different Python - if you have installed many versions.

I can't import a module in Python/Windows

I'm having problem when I trying to import a custom module I have which is very simple but I'm always getting:
Traceback (most recent call last):
File "demo_module1.py", line 12, in <module>
import mymodule
ModuleNotFoundError: No module named 'mymodule'
I have tried to set environment variables:
set PYTHONHOME=C:\Software\python-3.7.4
set PYTHONPATH=%PYTHONPATH%;C:\pyproys\test
Everything is located here: 'C:\pyproys\test'
The only way it works is if I add it directly in the code "But I don't want to do it in every single script I have so don't want to maintain it in that way".
import sys
sys.path.append('C:\pyproys\\test')
print(sys.path)
Here is the script I'm trying to run:
demo_module1.py
import mymodule
mymodule.greeting("Jonathan")
'mymodule.py' is in the same folder as 'demo_module1.py'
I'm expecting the code to run fine by just executing:
python demo_module1.py
Can someone please point me out what I'm doing wrong?
Try to find the directory /lib/site-packages in your Python folder in C drive and paste your module in that folder and then restart the system. Hope it'll solve your issue.

ModuleNotFoundError: No module named 'bayesnet'

I'm trying to use the OpenBayes module, but the problems start from the very first step :'(
When I try to import from OpenBayes
I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Мари\AppData\Local\Programs\Python\Python36\lib\site-packages\OpenBayes\__init__.py", line 7, in <module>
from bayesnet import *
ModuleNotFoundError: No module named 'bayesnet'
UPD: While installing (from .exe file) for py2 i gor error: "could not set a key value" (not a python error, but in dialog window)
I tried using pip install from console, but still get errors there.
Command "python setup.py egg_info" failed with error code 1 in C:\Users\CD3B~1\AppData\Local\Temp\pip-build-m4nnwa4o\OpenBayes\
Also not sure which py (2 or 3) is used when i type a command from console(
(Sorry for all that stupis questions)
You should
from OpenBayes import *
or
from OpenBayes import BNet
Here is an example demonstrating it's usage:
https://github.com/willasaywhat/OpenBayes-Fork/blob/master/Examples/bn_asia.py
I had the same problem and I created a directory with the same name as the root folder (within the root folder). Python then referred Its import calls to the src directory and not the folder. I also changed the python interpreter to a virtual (anaconda.exe), as the python install did not contain many of the modules that were being called by the application (flask, etc)
It's a weird workaround, but it worked for me. Hope this helps

run nupichelloworld in pycharm

I want to run nupichelloworld (https://github.com/lonesword/nupichelloworld) within pycharm but can't figure out how to force it to see nupic libraries. All sources -- nupic.core, nupic.sources, nupichelloworld etc are located on the same level (/home) (I am using the NUPIC-03-11-2014 image which I took from
https://mega.co.nz).
When I try to run it in console, that's all right, but pycharm tells following:
/usr/bin/python2.7 /home/nupic/nupichelloworld/helloworld.py
Traceback (most recent call last):
File "/home/nupic/nupichelloworld/helloworld.py", line 22, in <module>
import nupic
ImportError: No module named nupic
there is the such imports in the file:
from nupic.research.spatial_pooler import SpatialPooler as SP
import numpy as np
How to solve it? Thanx!
You probably need to configure the project's interpreter paths to include your package.

Categories

Resources