Spyder can not import plyfile - python

I have installed plyfile in the Scripts subdirectory of the Anaconda3 (I run Windows 10), using the pip3. When I enter the command
import plyfile
in the Python 3.5 Shell, the command is executed without problems.
But when I move to Spyder and I enter the same command in the console I receive an error message:
import plyfile
Traceback (most recent call last):
File "<ipython-input-3-db7ef797d821>", line 1, in <module>
import plyfile
ImportError: No module named 'plyfile'
I tried to add the path of the file to the environment using the Windows Commander and giving at the C:\ the command:
sys.path.append(C:\Users\Alexandros_7\Downloads\plyfile-0.4)
but I received the error message:
"sys.path.append" is not recognized as an internal or external command, operable program or batch file
I also tried the following commands from the console of Spyder:
import sys
sys.path.append("C:\\Users\\Alexandros\\Downloads\\plyfile")
These commands were executed without a problem. Then I entered, import plyfile and I received the same error message -- i.e. that "No module named "plyfile"".
Could you please help me?

try give Spyder the same environment paths like Anaconda, in your case the path to the installed plyfile eg.:
your_module is located in: "C:\Users\Alexandros\your_module.py"
in Spyder:
lets add the located path to the system environment
import sys
sys.path.append("C:\Users\Alexandros\") #need string
lets import your module
import your_module
reload(your_module)

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.

Getting an error for a module that I definitely imported

import pyinputplus as pyip
while True:
prompt='Want to know how to keep an idiot busy for hours?\n'
response=pyip.inputYesNo(prompt)
if response=='no':
break
print('Thank you. Have a nice day.')
When I run my above code , I get this error:
Traceback (most recent call last):
File "c:\users\XXXXXX\mu_code\idiot.py", line 1, in <module>
import pyinputplus as pyip
File "c:\users\XXXXXX\mu_code\pyinputplus\__init__.py", line 15, in <module>
import pysimplevalidate as pysv # type: ignore
ModuleNotFoundError: No module named 'pysimplevalidate'
I cannot figure it out. The module is definitely installed. I've even moved it from the folder it was originally installed in to the mu folder where the py file is saved. Any help would be appreciated.
The ModuleError says that you do not have pysimplevalidate installed.
Using the same python executable as you are using to run your script (idiot.py), run
python -m pip install pysimplevalidate
or, even more bullet-proof:
<path_to_python.exe> -m pip install pysimplevalidate
If you are not sure what python executable the script is using, you can check it with
# put this on top of your script
import sys
print(sys.executable) # will print C:\path\to\python.exe

No module named ib.message

I am trying to set up IBPY and Python on my Mac to run with Interactive Brokers. I have installed Git. I created a subdirectory ibapi under Home. I downloaded IBPy using git clone https://github.com/blampe/IbPy from the ibapi directory.
I am now trying to run the Demo.py program in Spyder. When I choose Run, I receive the error message:
ImportError: No module named Ib.Message
The first few lines of the demo program are:
import os
import sys
import time
import Ib.Message
import Ib.Socket
import Ib.Type
I am also trying to run a sample program: ib_api_demo from http://www.quantstart.com/articles/Using-Python-IBPy-and-the-Interactive-Brokers-API-to-Automate-Trades. When I try to run this, I get the error message:
ImportError: No module named ib.ext.Contract
The first few lines are:
from ib.ext.Contract import Contract
from ib.ext.Order import Order
from ib.opt import Connection, message
I figured this out. The problem was I was launching Spyder from my Mac Finder. When I did this, I received the error messages. When I launched Spyder (actually Anaconda Python) by typing "Spyder" in the Terminal window, this launched Anaconda Python. From here, I could run all my programs successfully with no errors.

Import error with module in Python 2.7

I've spent the better part of an afternoon trying to import the xlrd module, it works when i do it in the shell but when i try to run any file I get an import error.
Please could somebody provide a solution? (I'm a beginner, so please be excruciatingly specific)
This code:
#!/usr/bin/python
import os
os.chdir("C:/Users/User/Documents/Python/xlrd")
import xlrd
returns the error:
Traceback (most recent call last):
File "C:\Users\User\Documents\Python\Programs\Radiocarbon27.py", line 4 in <module>
import xlrd
ImportError: No module named xlrd
The path of the setup.py which contains the setup.py file is C:\Users\User\Documents\Python\xlrddocs
thanks!
Click the Start button, click All Programs, click Accessories, and then click Command Prompt.
Type Python then hit enter.
If you get the following, then you have to setup your environment variables.
'python' is not recognized as an internal or external command,
operable program or batch file.
If Python started, then you do not have to setup your environment variables.
Close the command prompt and open another one.
In the new command prompt type: cd C:\Users\User\Documents\Python\xlrddocs
Then type: Python setup.py install
That's it! Now in your .py file type:
import os
import xlrd
The xlrd package is not installed.
For example, you can do
$yum install python27_xlrd-0.9.3

Categories

Resources