如何使用Anaconda从Windows中的任何目录运行项目文件 [英] How to run project files using Anaconda from any directory in Windows

查看:1046
本文介绍了如何使用Anaconda从Windows中的任何目录运行项目文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处是Python新手.在朋友的推荐下正在使用Anaconda(在Windows 7上).

Python newbie here. Am using Anaconda (on Windows 7) by recommendation of a friend.

我想要做的是在Notepad ++中对我的类进行更改,然后立即在我的Python命令提示符窗口中对其进行测试.

What I want to be able to do is make a change to my class in Notepad++ and then test it in my Python command prompt window immediately.

这是一个简单的问题,我似乎找不到答案:Anaconda的默认安装希望在哪个目录中存储我的.py文件(以便可以使用import <MODULE NAME>轻松加载它们) ?

This is a simple question that I can't seem to find the answer: in what directory does a default installation of Anaconda expect me to be storing my .py files (so that I can easily load them using import <MODULE NAME>)?

我的PATH变量设置为: C:\USERS\<USERNAME>\Anaconda3;C:\USERS\<USERNAME>\Anaconda3\Scripts

My PATH variable is set to: C:\USERS\<USERNAME>\Anaconda3;C:\USERS\<USERNAME>\Anaconda3\Scripts

(这是默认设置)

我应该在Scripts目录下工作吗?那里已经有很多文件了.

Am I supposed to be working out of the Scripts directory...? There's already a lot of files in there.

大多数人做什么?也许将另一个文件夹添加到PATH变量并在那里工作?您是否为每个项目都将新文件夹添加到PATH中,还是有一种更有意义的方法?我已经有一个Projects目录,可用于其他所有内容.我只想在那里工作.

What do most people do? Perhaps add another folder to the PATH variable and work out of there? Do you add a new folder to PATH for each project or is there a way that makes more sense? I already have a Projects directory I use for everything else. I'd like to just be able to work out of there.

我正在使用记事本++进行编码.我真的不想打扰设置/学习IDE(我只是在做相对简单的I/O文件操作,就像以前在Excel中所做的那样……很恐怖).

I am coding in Notepad++. I don't really want to bother setting up/learning an IDE (I'm just doing relatively simple I/O file manipulation that I have previously been doing in Excel... the horror).

很抱歉,这个问题非常新手.我搜索了,找不到任何相关的内容.

Sorry for the extremely newbie question. I searched and could not find anything relevant.

在接受答案后进行

问题是我从开始"菜单运行python.exe.我没有意识到您应该在正在使用的文件夹(例如C:\USERS\<USERNAME>\MY PYTHON STUFF)中打开一个CMD窗口(SHIFT + RIGHT CLICK),然后从那里运行python.

The problem was that I was running python.exe from the Start menu. I did not realize that you are supposed to open a CMD window in the folder (SHIFT+RIGHT CLICK) you are working in (such as C:\USERS\<USERNAME>\MY PYTHON STUFF) and run python from there.

推荐答案

这可能就是您要尝试的.请注意,我也使用Anaconda.

This might be what you're attempting. Note that I also use Anaconda.

我的路径:

C:\Users\...\Documents\Python Scripts\

import_sample.py

class class_sample(object):

    def __init__(self):
        self.x = ["I", "am", "doing", "something", "with", "Python"]

test.py

from import_sample import class_sample

c = class_sample()
y = c.x
print " ".join(y)

结果:

I am doing something with Python
[Finished in 0.1s]

请注意,位于同一个文件夹中本身使我无需导入安装即可导入.基本上,只需确保所需的模块与main.py位于同一文件夹中就可以了.

Notice how being in the same folder allows me to import without having to install, per se. Basically, just make sure that the modules you need are in the same folder as your main.py and you're good.

从终端完成.

注意我如何cd进入上述文件夹并在其中激活python.由于我位于该文件夹中,因此可以与其中安装的其他系统级模块一起轻松导入其中的所有模块.

Notice how I cd into the above folder and activated python there. Since I was inside that folder, any modules inside it can be imported without any problems, alongside other system-wide modules installed as well.

这篇关于如何使用Anaconda从Windows中的任何目录运行项目文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆