run nupichelloworld in pycharm - python

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.

Related

Problem when importing a package from another directory

I want to import the function write_dynamic_data located in utilities.py into the file trigger_utilities.py which is lower in the hierarchy, but this error is showing up. How can I do? I'm avoiding to use sys.path as I've read it's a bag practise. I'm using Python 3.8.9 and I thinks it isn't necessary anymore).
Project stucture:
utilities.py
[processing]
trigger_utilities.py
This is the console output:
matidellatorre#MacBook-Pro-de-Mati myCode % /usr/bin/python3 /Users/matidellatorre/Desktop/Development/myCode/processing/trigger_utilities.py
Traceback (most recent call last):
File `"/Users/matidellatorre/Desktop/Development/myCode/processing/trigger_utilities.py", line 7, in <module>`
from ..utilities import write_dynamic_data
ImportError: attempted relative import with no known parent package
Thanks in advance!

import module failed with running by console

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.

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 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.

Python - cannot import slycot module in spyder (RuntimeError & ImportError)

When I try to import the slycot module in spyder (version 2.2), I get the following error:
RuntimeError: module compiled against API version 7 but this version of numpy is 6
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/slycot/__init__.py",
line 4, in <module>
from slycot.analysis import ab01nd,ab05md,ab05nd,ab07nd,ab08nd, ab09ad
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/slycot/analysis.py",
line 21, in <module>
from slycot import _wrapper
ImportError: numpy.core.multiarray failed to import
Now, when I import slycot in the python shell through my terminal, there are no problems at all. I think the reason why there are no problems through the terminal, is that I recently installed numpy 1.7.1. Spyder on the other hand still uses numpy 1.6.2.,hence the error.
I tried to change the numpy version in spyder, but so far that didn't work.
When I change the numpy(6) folder in my spyder lib with the recently installed numpy(7), I get the following error (in spyder):
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
What is the best way to solve this error?
Thanks in advance.
(Spyder dev here) At the moment it's not possible for the user to install anything inside the app. I guess you moved your slycot module from another interpreter to our App (because of the numpy error you mention).
The right way to use different modules not present in the app, is to change the path of your interpreter in:
Tools > Preferences > Console > Advanced settings > Python executable
If you installed slycot using your system Python, you have to select
/usr/bin/python

Categories

Resources